Update and rename First-one-to-pass-truth-test.md to first-one-to-pass-truth-test.md

This commit is contained in:
Angelos Chalaris
2017-12-16 14:40:03 +02:00
committed by GitHub
parent f504a8cf77
commit d7c2e3a017

View File

@ -1,13 +1,11 @@
### First-one-to-pass-truth-test
### First one to pass truth test
A function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument).
```
```js
findElement = (arr, func) => {
filterArr = arr.filter(func); //filter array with the function provided
return filterArr[0]; //return the first element that returns true, or undefined if no elements return true
}
// test here
findElement([1, 2, 3, 4], function(num){ return num !== 2 && num !== 1 }); //3 <- first element in array to be passed truth test
// findElement([1, 2, 3, 4], function(num){ return num !== 2 && num !== 1 }); //3 <- first element in array to be passed truth test
```