Let\'s say I have a string of numbers separated by spaces and I want to return the highest and lowest number. How could that best be done in JS using a function? Example: >
function highAndLow(numbers){ var temp = numbers.split(' '); temp.sort(function(a,b){return a-b; }); return temp[temp.length-1] + ' ' + temp[0]; }
did a little differently: first split into an array, then sorted ... and returned the last (maximum) element with the first (minimum) element