In this question, the candidate needs to implement a function
customSome that mimics the behaviour of
some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns
true if, in the array, it finds an element for which the provided function returns
true; otherwise it returns
false. It doesn't modify the array.
const array = [1, 2, 3, 4, 5]; // checks whether an element is even const even = (element) => element % 2 === 0; console.print(array.customSome(even)); // expected output: true
customSome takes two parameters
Function to execute on each value in the array. The function is called with the following arguments:
- The current element in the array.
- The index (position) of the current element in the array.
- The array that
customFindwas called on.
The callback must return a truthy value to indicate a matching element has been found.
Object to use as
this inside callbackFn.
true if the callback function returns a truthy value for at least one element in the array. Otherwise,
Start the timer, complete your solution, and test it against the test cases provided by the platform. Ideally, you should finish this question within 30 mins. Share your solution with us -- https://twitter.com/devtoolstech