File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,17 @@ exports.range = function (start) {
16
16
} ;
17
17
} ;
18
18
19
- exports . replicate = function ( count ) {
19
+ var replicate = function ( count ) {
20
+ return function ( value ) {
21
+ if ( count < 1 ) {
22
+ return [ ] ;
23
+ }
24
+ var result = new Array ( count ) ;
25
+ return result . fill ( value ) ;
26
+ } ;
27
+ } ;
28
+
29
+ var replicatePolyfill = function ( count ) {
20
30
return function ( value ) {
21
31
var result = [ ] ;
22
32
var n = 0 ;
@@ -27,6 +37,11 @@ exports.replicate = function (count) {
27
37
} ;
28
38
} ;
29
39
40
+ // In browsers that have Array.prototype.fill we use it, as it's faster.
41
+ exports . replicate = typeof Array . prototype . fill === "function" ?
42
+ replicate :
43
+ replicatePolyfill ;
44
+
30
45
exports . fromFoldableImpl = ( function ( ) {
31
46
// jshint maxparams: 2
32
47
function Cons ( head , tail ) {
You can’t perform that action at this time.
0 commit comments