0
Why does this not print the smallest number and instead prints 0?
4 odpowiedzi
+ 3
Use the for in loop with objects to iterate over the keys. To iterate over the values of an iterable you must use the for of loop.
At line 3 make in as of.
+ 2
for(x in array) returns the index of each elem in the array .
try
for(x of array)
0
you could use reduce() array method:
function smallestNum(array) {
return array.reduce(
(a,v) => v<a ? v : a,
Infinity
);
}
0
Thanks I didn't understand the difference between in/of and thought they were interchangable