File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
22function randomItemWithNoRepetition ( array ) {
33 if ( ! Array . isArray ( array ) || array . length === 0 ) return - 1 ;
4- var copy = array . slice ( ) ;
4+ var copyOfArray = array . slice ( ) ;
55 return function ( ) {
6- copy . length < 1 && ( copy = array . slice ( ) ) ;
7- var index = Math . floor ( Math . random ( ) * copy . length ) ,
8- item = copy [ index ] ;
9- return copy . splice ( index , 1 ) , item ;
6+ copyOfArray . length < 1 && ( copyOfArray = array . slice ( ) ) ;
7+ var index = Math . floor ( Math . random ( ) * copyOfArray . length ) ,
8+ item = copyOfArray [ index ] ;
9+ return copyOfArray . splice ( index , 1 ) , item ;
1010 } ;
1111}
1212
Original file line number Diff line number Diff line change 11{
22 "name" : " @smakss/random-array-element" ,
3- "version" : " 1.1.4 " ,
3+ "version" : " 1.1.5 " ,
44 "description" : " Selects a random unique array element without repetition from provided array." ,
55 "type" : " module" ,
66 "main" : " ./index.cjs" ,
You can’t perform that action at this time.
0 commit comments