Write a program to sort numerical array in Javascript.
Example:
Input: arr=[10,7,5,25,2,3]
Output: arr = [2,3,5,7,10,25]
Approach
JavaScript
var points = [10,7,5,25,2,3];console.log("input:"+points);//return (b-a) in case of descending orderpoints.sort(function(a, b){return a-b})console.log("output:"+points);
No comments:
Post a Comment