Created
December 28, 2017 21:45
-
-
Save crystalattice/d348efa0cf5c898810ab5d48b224b1c4 to your computer and use it in GitHub Desktop.
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
//Make List | |
function makeList(item1, item2, item3) { | |
return list = [item1, item2, item3]; | |
} | |
//Add to array | |
function addToList(list, item) { | |
var list = list; | |
list.push(item); | |
return list; | |
} | |
//Access array | |
function accessFirstItem(array) { | |
return array[0]; | |
} | |
function accessThirdItem(array) { | |
return array[2]; | |
} | |
//Length | |
function findLength(array) { | |
return array.length; | |
} | |
function accessLastItem(array) { | |
return array[array.length - 1]; | |
} | |
//Slicing | |
function firstFourItems(array) { | |
var new_array = array.slice(0, 4); | |
return new_array; | |
} | |
function lastThreeItems(array) { | |
var new_array = array.slice(-3); | |
return new_array; | |
} | |
//Array copying | |
function minusLastItem(array) { | |
array.pop(); | |
return array; | |
} | |
function copyFirstHalf(array) { | |
var new_array = []; | |
var length = Math.floor(array.length/2); | |
console.log(length); | |
if (array.length % 2 != 0) { | |
new_array = array.slice(0, length);} | |
else { | |
new_array = array.slice(0, array.length/2)} | |
return new_array; | |
} | |
//Squares | |
function squared(num){ | |
return num * num;} | |
function squares(array) { | |
return array.map(squared); | |
} | |
//Reverse sort | |
function reverse(a, b){ | |
return b-a; | |
} | |
function greatestToLeast(array) { | |
return array.sort(reverse); | |
} | |
//String length | |
function length(string){ | |
return string.length < 5; | |
} | |
function shortWords(array) { | |
return array.filter(length); | |
} | |
//Find | |
function divisor(num){ | |
return num % 5 === 0; | |
} | |
function divisibleBy5(array) { | |
return array.find(divisor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment