Just a matter of curiosity. With the reduce function, we could easily find the smallest and largest number inside the array separately. Similar:
var a = [1,2,3,4,5,1,-1,6,7,8,9,10,2,11]; a.reduce(function(prev,cur,index,array){ return prev > cur ? prev : cur; });
Given that this doesn't work?
var a = [1,2,3,4,5,1,-1,6,7,8,9,10,2,11]; var smallest = 0; var biggest = 0; a.reduce(function(prev,cur,index,array){ smallest = prev < cur ? prev : cur; biggest = prev > cur ? prev : cur; }); console.log([smallest, biggest]);
Tested on repl.it.