Skip to content

Instantly share code, notes, and snippets.

@andrewserong
Created January 8, 2020 05:56
Show Gist options
  • Save andrewserong/39d2867c08972de89b4d090801a67005 to your computer and use it in GitHub Desktop.
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)
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