Skip to content

Instantly share code, notes, and snippets.

View AliceWonderland's full-sized avatar
:octocat:

Alice Chuang AliceWonderland

:octocat:
View GitHub Profile
@AliceWonderland
AliceWonderland / 5.7 Rotate Array.js
Created April 12, 2017 05:30 — forked from anonymous/5.7 Rotate Array.js
5.7 Rotate Array created by smillaraaq - https://repl.it/HE2f/3
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));
@AliceWonderland
AliceWonderland / 5.6 My Slice.js
Created April 12, 2017 05:30 — forked from anonymous/5.6 My Slice.js
5.6 My Slice created by smillaraaq - https://repl.it/HEZ7/1
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);
}
@AliceWonderland
AliceWonderland / 5.5 My LastIndexOf.js
Created April 12, 2017 05:29 — forked from anonymous/5.5 My LastIndexOf.js
5.5 My LastIndexOf created by smillaraaq - https://repl.it/HEWJ/1
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;
}
@AliceWonderland
AliceWonderland / 5.4 My Join.js
Created April 12, 2017 05:29 — forked from anonymous/5.4 My Join.js
5.4 My Join created by smillaraaq - https://repl.it/HEVr/3
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) {
@AliceWonderland
AliceWonderland / 5.3 My Unshift.js
Created April 12, 2017 05:29 — forked from anonymous/5.3 My Unshift.js
5.3 My Unshift created by smillaraaq - https://repl.it/HET3/2
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];
@AliceWonderland
AliceWonderland / 5.2 Even and Odd.js
Created April 12, 2017 05:29 — forked from anonymous/5.2 Even and Odd.js
5.2 Even and Odd created by smillaraaq - https://repl.it/HERy/2
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]);
}
@AliceWonderland
AliceWonderland / 5.1 Debug Hunt.js
Created April 12, 2017 05:28 — forked from anonymous/5.1 Debug Hunt.js
5.1 Debug Hunt created by smillaraaq - https://repl.it/HERJ/0
Empty file
@AliceWonderland
AliceWonderland / 4.5 Make Grid.js
Created April 7, 2017 01:40 — forked from anonymous/4.5 Make Grid.js
4.5 Make Grid created by smillaraaq - https://repl.it/GzQn/6
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);
}
@AliceWonderland
AliceWonderland / 4.4 Array Flattener.js
Created April 7, 2017 01:24 — forked from anonymous/4.4 Array Flattener.js
4.4 Array Flattener created by smillaraaq - https://repl.it/GzQT/1
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]);
}
@AliceWonderland
AliceWonderland / 4.3 Zoo Inventory.js
Created April 7, 2017 01:12 — forked from anonymous/4.3 Zoo Inventory.js
4.3 Zoo Inventory created by smillaraaq - https://repl.it/GzMe/8
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++){