Created
January 19, 2018 22:01
-
-
Save schamblee/c8952528323bdb2d0b81f18c937439fe 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
Array copying I | |
function firstFourItems(array) { | |
return array.slice(0, 4) | |
} | |
function lastThreeItems(array) { | |
return array.slice(-3) | |
} | |
Array copying II | |
function minusLastItem(array) { | |
return array.slice(0, array.length-1); | |
} | |
function copyFirstHalf(array) { | |
return array.slice(0, array.length/2) | |
} | |
Squares with map | |
function squares(array) { | |
return array.map(num => num ** 2); | |
} | |
Sort | |
function greatestToLeast(array) { | |
return array.sort((a, b) => b - a); | |
} | |
Filter | |
function shortWords(array) { | |
return array.filter(function (word) { | |
return word.length < 5; | |
}); | |
} | |
function divisibleBy5(array) { | |
return array.find(num => num % 5 === 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment