Array.prototype.newInclude = function(element, index) {
let startIndex = index || 0,
arr = this.slice(startIndex);
for (let i = 0; i < arr.length; i++) {
if (element === arr[i] || isNaN(arr[i]) && isNaN(element)) {
return true;
}
}
return false;
}
['a','b'].newInclude('a') // true
['a','b'].newInclude('e') // true
that is , all the characters give true. I understand that this is using isNaN, but where would I tweak?[1,2,3,NaN].newInclude(NaN) // => true
NaN !== NaN // true
isNaN(undefined); // true
isNaN({}); // true
isNaN('test'); // true
Find more questions by tags JavaScript