Return highest and lowest number in a string of numbers with spaces
问题 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: highestAndLowest("1 2 3 4 5"); // return "5 1" I would like the both numbers to be returned in a string. The lowest number first followed by a space then the highest number. Here is what I have so far: function myFunction(str) { var tst = str.split(" "); return tst.max(); } 回答1: You can use Math.min and Math.max, and use them