As in title I want to return true if any element of array is equal to n or sum of two elements of array is equal to n. So if array is [1,4,5] and n is 1 or 4 or 5 or 6 or 9 I want to get true. Here's my code:
function checkArray (x, array) {
return array.includes(x) || array.some((item, i) => array.slice(i+1).includes(x-item));
}
It works fine but is using "some" the best way in terms of performance? How can I improve execution speed?
Edit: Negative numbers are allowed