Sort 2D array in JavaScript -


i'm trying sort numbers in each array greatest smallest, first 1 being sorted. need nested loop? i'm stuck.

function sortnums(arr) {   for(var = 0; < arr.length; i++){      arr[i] = arr[i].sort(function(a, b){return b-a;});      return arr;    } }  sortnums([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]); 

when using return keyword function terminated. move outside iteration , should good:

function sortnums(arr) {   for(var = 0; < arr.length; i++) {      arr[i] = arr[i].sort(function(a, b) {        return b - a;      });   }   return arr; }  sortnums([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]); 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -