-
-
Save codecademydev/bb57dcf8256137e6d9840ce9f1bcd1ae to your computer and use it in GitHub Desktop.
Codecademy export
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
//challenge 1: define a callback function before you use it an iterator | |
const capitals = [ 'Amsterdam', 'London', 'Brussels', 'Oslo', 'Stockholm', 'Paris', 'Ankara', 'Alberta']; | |
const cityA = cityA => { //callback function | |
return cityA[0] === 'A'; | |
}; | |
const startsWithA=capitals.filter(cityA); //iterator | |
console.log(startsWithA); | |
//challenge 2: chain two iteration methods | |
const shortCity=startsWithA.some(city => city.length < 7); | |
//challenge 3, use optional arguments in an iterator | |
console.log(capitals.indexOf('Brussels', 0)); //should return 2 | |
// challenge 4: return a single array from a multilayer array | |
const numbers = [[1,2],[3,4],[5,6],[7,8]]; | |
let newArray = numbers.reduce(function(accumulator, currentValue) { | |
return accumulator.concat(currentValue); | |
}, | |
[] | |
); | |
console.log(newArray); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment