FCC Intermediate Algorithm Scripting: Drop it


Given the array arr, iterate through and remove each element starting from the first element (the 0 index) until the function funcreturns truewhen the iterated element is passed through it.
Then return the rest of the array once the condition is satisfied, otherwise, arrshould be returned as an empty array.

function dropElements(arr, func) {
// Drop them elements.
for (let i = 0; i < arr.length; i++) {
if (func(arr[i]) === true) {
arr.splice(0, i);
return arr;
}
}
arr.splice(0, arr.length);
return arr;
}

dropElements([1, 2, 3], function(n) {return n < 3; });

Comments

Popular posts from this blog

Code Wars: Data Reverse (6 kyu)

Code Wars: longest_palindrome (6 kyu)

Code Wars: Find the odd int