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: >
You can use Math.min and Math.max, and use them in an array to return the result, try:
function highestAndLowest(numbers){ numbers = numbers.split(" "); return Math.max.apply(null, numbers) + " " + Math.min.apply(null, numbers) } document.write(highestAndLowest("1 2 3 4 5"))