7-12
(1) Find the position of the element item in the given array arr:
function IndexOf (arr, item) { var flag =-1; for (var key in arr) { if (arr[key] = = Item) { flag = key; } } return flag;}
(2) calculates the sum of all the elements in the given array of arr
function sum (SRR) { var sum = 0; for (var key in arr) { sum + = Arr[key]; } return sum; }
(3) Remove the array of all values in arr that are equal to item, do not directly modify the array arr, the result returns the new Year's arrays
function Remove (arr,item) { var newArr = []; for (var key in arr) { if (Arr[key]) { newarr.push (Arr[key]); } } return NEWARR; }
7-13
(1) Add the element item at the end of the array arr. Do not directly modify the array arr, the result returns a new array
function Append (arr, item) { var newarr=[]; Newarr=arr.slice (0); Newarr.push (item); return NEWARR;}
(2) Delete the first element of the array arr. Do not directly modify the array arr, the result returns a new array
function Curtail (arr) { var newarr=[]; Newarr=arr.slice (0); Newarr.shift (); return NEWARR;}
(3) Add the element item to the index of the array arr. Do not directly modify the array arr, the result returns a new array
function Insert (arr, item, index) { var newarr=[]; Newarr=arr.slice (0); Newarr.splice (Index,0,item); return NEWARR;}
Not to be continued ...
JS programming Little Practice-New Ket &imweb