Created
August 9, 2017 11:52
-
-
Save jamessergeant/7fce8f764407fc00530a0a3e5ff0deeb 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
function makeList(item1, item2, item3) { | |
return [item1, item2, item3]; | |
} | |
function addToList(list, item) { | |
list.push(item); | |
return list; | |
} | |
function accessFirstItem(array) { | |
return array[0]; | |
} | |
function accessThirdItem(array) { | |
return array[2]; | |
} | |
function findLength(array) { | |
return array.length; | |
} | |
function accessLastItem(array) { | |
return array[array.length-1]; | |
} | |
function firstFourItems(array) { | |
return array.slice(0,4); | |
} | |
function lastThreeItems(array) { | |
return array.slice(array.length-3,array.length) | |
} | |
function minusLastItem(array) { | |
return array.slice(0,array.length-1); | |
} | |
function copyFirstHalf(array) { | |
return array.slice(0,Math.floor(array.length/2)) | |
} | |
function squares(array) { | |
return array.map(function(num) { | |
return num ** 2; | |
}); | |
} | |
function greatestToLeast(array) { | |
return array.sort(function(a, b){return a-b}).reverse() | |
} | |
function shortWords(array) { | |
return array.filter(function(word){return word.length < 5}) | |
} | |
function divisibleBy5(array) { | |
return array.find(function(num){return !(num % 5)}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment