function getComparator ( n ) { return function ( a, b ) { return a[ n ] - b[ n ] } } arr.sort( getComparator( 1 ) )