Bonfire 33: Finders Keepers

TASK: Create a function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument).


function find(arr, func) {

var winners = arr.filter(func);
return winners[0];

}

find([1, 2, 3, 4], function(num){ return num % 2 === 0; });

Advertisements
Bonfire 33: Finders Keepers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s