File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -590,19 +590,28 @@ var _ = {};
590
590
_ . sortBy = function ( collection , iterator ) {
591
591
//apply iterator to collection
592
592
593
+ //sort by key
593
594
if ( typeof iterator === 'string' ) {
594
595
return collection . sort ( function ( a , b ) {
595
- return ( a [ iterator ] - b [ iterator ] ) ;
596
+ if ( a [ iterator ] === undefined ) {
597
+ return 1 ;
598
+ } else {
599
+ return ( a [ iterator ] - b [ iterator ] ) ;
600
+ }
596
601
} ) ;
597
- } else {
602
+ } else { //sort by function
598
603
var iterated = [ ] ;
599
604
var newCollection = [ ] ;
600
605
_ . each ( collection , function ( val ) {
601
606
iterated . push ( [ val , iterator ( val ) ] ) ;
602
607
} ) ;
603
608
604
609
iterated . sort ( function ( a , b ) {
605
- return a [ 1 ] - b [ 1 ] ;
610
+ if ( a [ 1 ] === undefined ) {
611
+ return 1 ;
612
+ } else {
613
+ return a [ 1 ] - b [ 1 ] ;
614
+ }
606
615
} ) ;
607
616
_ . each ( iterated , function ( val ) {
608
617
newCollection . push ( val [ 0 ] ) ;
You can’t perform that action at this time.
0 commit comments