Skip to content

Commit fbb41ce

Browse files
committed
feat(#309): Address feedback from code review
Using static check to determine if `Array.prototype.flatMap` is available, and use `var` instead of `let` in for loop to match existing code style.
1 parent bed2304 commit fbb41ce

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/Control/Bind.js

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
export const arrayBind = function (arr) {
2-
if (typeof Array.prototype.flatMap === "function") {
3-
return function (f) {
4-
return arr.flatMap(f);
5-
};
6-
}
7-
8-
return function (f) {
9-
const result = [];
10-
for (let i = 0, l = arr.length; i < l; i++) {
11-
const xs = f(arr[i]);
12-
for (let j = 0, m = xs.length; j < m; j++) {
13-
result.push(xs[j]);
14-
}
1+
export const arrayBind =
2+
typeof Array.prototype.flatMap === "function"
3+
? function (arr) {
4+
return function (f) {
5+
return arr.flatMap(f);
6+
};
157
}
16-
return result;
17-
};
18-
};
8+
: function (arr) {
9+
return function (f) {
10+
var result = [];
11+
var l = arr.length;
12+
for (var i = 0; i < l; i++) {
13+
var xs = f(arr[i]);
14+
var k = xs.length;
15+
for (var j = 0; j < k; j++) {
16+
result.push(xs[j]);
17+
}
18+
}
19+
return result;
20+
};
21+
};

0 commit comments

Comments
 (0)