From d7c2e3a017997789eb6b72fed4d6569991f8980a Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 16 Dec 2017 14:40:03 +0200 Subject: [PATCH] Update and rename First-one-to-pass-truth-test.md to first-one-to-pass-truth-test.md --- ...pass-truth-test.md => first-one-to-pass-truth-test.md} | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) rename snippets/{First-one-to-pass-truth-test.md => first-one-to-pass-truth-test.md} (66%) diff --git a/snippets/First-one-to-pass-truth-test.md b/snippets/first-one-to-pass-truth-test.md similarity index 66% rename from snippets/First-one-to-pass-truth-test.md rename to snippets/first-one-to-pass-truth-test.md index 0732eb51c..cea62dd43 100644 --- a/snippets/First-one-to-pass-truth-test.md +++ b/snippets/first-one-to-pass-truth-test.md @@ -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 ```