View on GitHub

marymafa.github.io


layout: post title: Finders Keepers date: 2017-11-16 —

Finders Keepers

I were asked to 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).

My Approach

method 1

I created a function title find element and passes the parameters named arr and func.

method 2

I have created a for loop that will iterate though the each arguments. On the test statement i said if func(arr[i] is true then return arra[i] meaning that it checks if the result on the function are true or not then return and if is true should return the element of an that will pass through the argument.

method 3

I created another function that will return number in an array that are divisible by two and leaves a remainder which is zero.

Finally , i tested the test it was working and it returned eight and undefined following the instructions.