This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function rotate(myArray, n){ | |
| //num=num % arr.length; //check for if num is greater than length of Array | |
| var begin=-n; | |
| if(n===0){ | |
| return console.log(myArray); | |
| } | |
| console.log(begin); | |
| var spliced=myArray.splice(begin); | |
| return console.log(spliced.concat(myArray)); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mySlice (arr,begin,end) { | |
| var newArr = []; | |
| var start = (begin)?begin:0; | |
| start = (begin<0)?arr.length+begin:start; | |
| var terminate = (end)?end:arr.length-1; | |
| for (let i = start ; i <= terminate ; i++){ | |
| newArr.push(arr[i]); | |
| } | |
| return console.log(newArr); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function myLastIndexOf(arr, searchItem, fromIndex){ | |
| var startIndex=(fromIndex)?fromIndex:arr.length-1; | |
| var output= -1; | |
| for(var i=startIndex;i>=0;i--){ | |
| if(arr[i]===searchItem){ | |
| return output= i; | |
| } | |
| } | |
| return output; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function myJoin(arr,sep) { | |
| let str = ""; | |
| if (!sep) { sep = ","; } | |
| for (let i = 0 ; i < arr.length ; i ++) { | |
| if (arr[i] === undefined||arr[i] === null) { | |
| continue; | |
| } | |
| if (!!str.length) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function myUnshift (arr,num) { | |
| arr.splice(0,0,num); | |
| return arr; | |
| } | |
| console.log(myUnshift([1,3,4],2)); | |
| function myUnshift (arr,num) { | |
| var tempArray=[num]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function evenOdd(myArray){ | |
| var oddArray=[]; | |
| var evenArray=[]; | |
| var combinedArray=[]; | |
| for(var i=0;i<myArray.length;i++){ | |
| if(!(i%2)){ | |
| evenArray.push(myArray[i]); | |
| }else{ | |
| oddArray.push(myArray[i]); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Empty file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function makeGrid(row,col){ | |
| debugger; | |
| var grid=[]; | |
| for(i=0;i<row;i++){ | |
| var gridRow=[]; | |
| for(x=1;x<=col;x++){ | |
| gridRow.push(x); | |
| } | |
| grid.push(gridRow); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function flatten(argArray){ | |
| var newArray=[]; | |
| for(i=0;i<argArray.length;i++){ | |
| if(typeof argArray[i]==="object"){ | |
| for(x=0;x<argArray[i].length;x++){ | |
| newArray.push(argArray[i][x]); | |
| } | |
| }else{ | |
| newArray.push(argArray[i]); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myZoo = [ | |
| ["King Kong", ["gorilla", 42]], | |
| ["Nemo", ["fish", 5]], | |
| ["Punxsutawney Phil", ["groundhog", 11]] | |
| ]; | |
| function zooInventory(myZoo){ | |
| var theMessage=""; | |
| for(var i=0; i<myZoo.length;i++){ |