1
1
"use strict" ;
2
2
3
+ function _toConsumableArray ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } else { return Array . from ( arr ) ; } }
4
+
3
5
Array . prototype . insert = function ( index ) {
4
- index = Math . min ( index , this . length ) ;
5
- arguments . length > 1 && this . splice . apply ( this , [ index , 0 ] . concat ( [ ] . pop . call ( arguments ) ) ) && this . insert . apply ( this , arguments ) ;
6
- return this ;
6
+ index = Math . min ( index , this . length ) ;
7
+ arguments . length > 1 && this . splice . apply ( this , [ index , 0 ] . concat ( [ ] . pop . call ( arguments ) ) ) && this . insert . apply ( this , arguments ) ;
8
+ return this ;
7
9
} ;
8
10
9
11
Array . prototype . remove = function ( ) {
10
- var _arguments = arguments ,
11
- _this = this ;
12
-
13
- // If no arguments passed into remove function
14
- if ( arguments . length <= 0 ) {
15
- // Should do nothing
16
- return this ;
17
- }
18
- delete arguments . length ;
19
- var indexesToRemove = Object . keys ( arguments ) . map ( function ( key ) {
20
- return _arguments [ key ] ;
21
- } ) . sort ( function ( a , b ) {
22
- return b - a ; // sort descending order
23
- } ) ;
24
- indexesToRemove . forEach ( function ( index ) {
25
- if ( _this [ index ] != undefined && _this [ index ] != null && index >= 0 && index < _this . length ) {
26
- _this . splice ( index , 1 ) ;
27
- }
28
- } ) ;
29
- return this ;
12
+ var _arguments = arguments ,
13
+ _this = this ;
14
+
15
+ // If no arguments passed into remove function
16
+ if ( arguments . length <= 0 ) {
17
+ // Should do nothing
18
+ return this ;
19
+ }
20
+ delete arguments . length ;
21
+ var indexesToRemove = Object . keys ( arguments ) . map ( function ( key ) {
22
+ return _arguments [ key ] ;
23
+ } ) . sort ( function ( a , b ) {
24
+ return b - a ; // sort descending order
25
+ } ) ;
26
+ indexesToRemove . forEach ( function ( index ) {
27
+ if ( _this [ index ] != undefined && _this [ index ] != null && index >= 0 && index < _this . length ) {
28
+ _this . splice ( index , 1 ) ;
29
+ }
30
+ } ) ;
31
+ return this ;
30
32
} ;
31
33
32
34
Array . prototype . shuffle = function ( ) {
33
- var currentIndex = this . length ;
34
- var temporaryValue ;
35
- var randomIndex ;
35
+ var currentIndex = this . length ;
36
+ var temporaryValue ;
37
+ var randomIndex ;
36
38
37
- while ( 0 !== currentIndex ) {
38
- randomIndex = Math . floor ( Math . random ( ) * currentIndex ) ;
39
- currentIndex -= 1 ;
39
+ while ( 0 !== currentIndex ) {
40
+ randomIndex = Math . floor ( Math . random ( ) * currentIndex ) ;
41
+ currentIndex -= 1 ;
40
42
41
- temporaryValue = this [ currentIndex ] ;
42
- this [ currentIndex ] = this [ randomIndex ] ;
43
- this [ randomIndex ] = temporaryValue ;
44
- }
43
+ temporaryValue = this [ currentIndex ] ;
44
+ this [ currentIndex ] = this [ randomIndex ] ;
45
+ this [ randomIndex ] = temporaryValue ;
46
+ }
45
47
46
- return this ;
48
+ return this ;
47
49
} ;
48
50
49
51
Array . prototype . randomElement = function ( ) {
50
- return this [ Math . floor ( Math . random ( ) * this . length ) ] ;
52
+ return this [ Math . floor ( Math . random ( ) * this . length ) ] ;
51
53
} ;
52
54
53
55
Array . prototype . swap = function ( a , b ) {
54
- if ( ! this [ a ] || ! this [ b ] ) {
55
- return this ;
56
- }
57
- var tmp = this [ a ] ;
58
- this [ a ] = this [ b ] ;
59
- this [ b ] = tmp ;
60
- return this ;
56
+ if ( ! this [ a ] || ! this [ b ] ) {
57
+ return this ;
58
+ }
59
+ var tmp = this [ a ] ;
60
+ this [ a ] = this [ b ] ;
61
+ this [ b ] = tmp ;
62
+ return this ;
63
+ } ;
64
+
65
+ Array . prototype . max = function ( ) {
66
+ return Math . max . apply ( Math , _toConsumableArray ( this ) ) ;
67
+ } ;
68
+
69
+ Array . prototype . min = function ( ) {
70
+ return Math . min . apply ( Math , _toConsumableArray ( this ) ) ;
61
71
} ;
0 commit comments