Create a difference function that takes two arrays as arguments and returns an array containing the elements that are present in the first array but not in the second array. The function should avoid redundant operations on duplicate values.
Create a dropWhile function that takes two parameters:
array: The input array, which can be of any typepredicate: A predicate function that takes an element from the array and returns a Boolean value. If the predicate returns true, the element should be discarded.The dropWhile function should return a new array without modifying the original array. The returned array should start from the first element in the original array that does not satisfy the predicate condition and include all subsequent elements until the end of the array. If every element satisfies the predicate function, an empty array should be returned.
console.log(dropWhile([1, 2, 3, 4, 5, 6], (value) => value < 4)); // => [4, 5, 6]
console.log(dropWhile([0, 1, 2], (value) => value < 5)); // => []
console.log(dropWhile([0, 6, 1, 2], (value) => value < 5)); // => [6, 1, 2]
function dropWhile(arr,predicate){
let index = 0
for(item of arr){
if(!predicate(item)){
break
}else{
index++
}
}
return arr.slice(index)
}
function dropWhile(array, predicate) {
let index = 0
while (index < array.length && predicate(array[index])) {
index++
}
return array.slice(index)
}