+ 1
why this code doesn't return the right output for number greater than 9 ?
const arr = [10, 11, 7, 5, 100, 6, 4, 3, 8, 9]; function num(e) { for (let e of arr) { if (e.toString().split('').includes('10')) { return 'Yay num found'; } } return 'Num not found'; } console.log(num(arr)); // the output will be Num not found // and the output supposed to be yay num found and if i check num less than 10 I get the correct output!
1 ответ
+ 3
Let us take the 1st element which is 10
e.toString().split('') returns ['1','0'] which doesn't have a '10'. So it will never become true. Hope you get the point.