0

Why does this not print the smallest number and instead prints 0?

https://code.sololearn.com/cY9u7q2D8JbY/?ref=app

18th Mar 2021, 9:36 AM
Cameron J Hughes-Daly
Cameron J Hughes-Daly - avatar
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.
18th Mar 2021, 9:44 AM
Avinesh
Avinesh - avatar
+ 2
for(x in array) returns the index of each elem in the array . try for(x of array)
18th Mar 2021, 9:45 AM
Med Amine Fh
Med Amine Fh - avatar
0
you could use reduce() array method: function smallestNum(array) { return array.reduce( (a,v) => v<a ? v : a, Infinity ); }
18th Mar 2021, 9:53 AM
visph
visph - avatar
0
Thanks I didn't understand the difference between in/of and thought they were interchangable
18th Mar 2021, 4:43 PM
Cameron J Hughes-Daly
Cameron J Hughes-Daly - avatar