Learn JavaScript Episode #20: Exercise Solution

preview_player
Показать описание
Get The Learn to Code Course Bundle!

Hopefully everyone managed to solve the previous exercise. If not, it's okay. If you did, great job! It probably took you multiple times unless you come from a programming background. This is a fairly simply problem, and so if you want see my take on it keep watching. I'm going to create a function first to compute this, and we're going to use a for loop to find the missing number in the array.
Рекомендации по теме
Комментарии
Автор

I used the solution code provided, but the result is always wrong.

function missingno(numbers){
var missing = -1;

for (var i = 0; i <= numbers.length; i++){
if(numbers.indexOf(i) === -1){
missing = i;
}
}

return missing;
}

var numbers = [15, 1, 2, 10, 3, 14, 10, 8];


fahadh
Автор

what if the interviewer says to find the missing numbers in an array //Input: [9, 6, 2, 3, 5, 7, 0, 1] //Output:4, 8 ? while loop ? tia David

DavidLarew
Автор

how about if array length is like in that case it looped like 1 lack times so this is not good solution. how can be optimise it

singhkumardev
Автор

nice tutorial.

I would say (i <= numbers.length - 1) adds more complexity than (i < numbers.length)

greatnile
Автор

thanks man, very help :)..*new subscribe;)

bijaksetiapsaat