Created
October 1, 2019 21:50
-
-
Save gusmcnair/8f17afe4e8172a5d43df8b57cc15cbe3 to your computer and use it in GitHub Desktop.
This file contains 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 drill | |
function makeList(item1, item2, item3) { | |
const arr = [item1, item2, item3]; | |
return arr; | |
} | |
Add to list drill | |
function addToList(list, item) { | |
list.push(item); | |
return list; | |
} | |
Access first and third items | |
function accessFirstItem(array) { | |
return (array[0]); | |
} | |
function accessThirdItem(array) { | |
return (array[2]); | |
} | |
Array length and access | |
function findLength(array) { | |
return (array.length); | |
} | |
function accessLastItem(array) { | |
return array.pop(); | |
} | |
Array copying I | |
function firstFourItems(array) { | |
return array.slice(0, 4); | |
} | |
function lastThreeItems(array) { | |
return array.slice(-3); | |
} | |
Array copying II | |
function minusLastItem(array) { | |
const lengthMinusOne = array.length - 1 | |
return array.slice(0, lengthMinusOne) | |
} | |
function copyFirstHalf(array) { | |
const halfArray = (array.length / 2) | |
return array.slice(0, halfArray) | |
} | |
Squares with map | |
function squares(array) { | |
function squared(num) { | |
return (num ** 2); | |
} | |
return array.map(squared); | |
} | |
Sort greatest to least | |
function greatestToLeast(array) { | |
function sortGreatest(a, b){ | |
return b-a; | |
} return array.sort(sortGreatest); | |
} | |
Filter | |
function shortWords(array) { | |
function lessThanFive(num) { | |
return num.length < 5; | |
} return array.filter(lessThanFive) | |
} | |
Find | |
function divisibleBy5(array) { | |
function divisible(num) { | |
return num % 5 === 0; | |
} return array.find(divisible); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment