-
-
Save andrewserong/39d2867c08972de89b4d090801a67005 to your computer and use it in GitHub Desktop.
Interview question of the week from Cassidoo's newsletter (implement array.filter() by hand)
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
function arrayFilter( arrayToFilter, comparison ) { | |
const filteredArray = []; | |
arrayToFilter.map( item => { | |
if ( comparison( item ) === true ) { | |
filteredArray.push( item ); | |
} | |
} ); | |
return filteredArray; | |
} | |
const a1 = [ 'apples', 'oranges', 'bananas' ]; | |
const a2 = arrayFilter( a1, item => item !== 'oranges' ); | |
console.log( a1 ); | |
console.log( a2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment