Created
October 2, 2018 06:34
-
-
Save jepras/035b7954a7fbc15395157b8e05b170b2 to your computer and use it in GitHub Desktop.
Used a function as a input to check for Boolean. Used splice to remove first index in array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dropElements(arr, func) { | |
// Drop them elements. | |
for (var i = 0; i <= arr.length; i++) { | |
// Check console for current value | |
console.log("function is " + func(arr[0])); | |
console.log("value is " + arr[0]) | |
// remove value from arr if function returns false | |
if(func(arr[0]) === false) { | |
console.log("removed " + arr[0]) | |
arr.splice(0,1) | |
} | |
// return arr if function returns true | |
if(func(arr[0]) === true) { | |
return arr; | |
} | |
} | |
// else empty array | |
return []; | |
} | |
dropElements([1, 2, 3, 7, 4], function(n) {return n > 3;}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment