Skip to content

Commit

Permalink
Move the depth guard to the internal flatten
Browse files Browse the repository at this point in the history
Manual testing revealed that flattening with depth=false behaved as a
shallow flatten instead of a deep one.
  • Loading branch information
jgonggrijp committed Jul 27, 2020
1 parent 9ba5a6c commit 7d37875
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
5 changes: 5 additions & 0 deletions modules/_flatten.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import isArguments from './isArguments.js';
// Internal implementation of a recursive `flatten` function.
export default function flatten(input, depth, strict, output) {
output = output || [];
if (!depth && depth !== 0) {
depth = Infinity;
} else if (depth <= 0) {
return output.concat(input);
}
var idx = output.length;
for (var i = 0, length = getLength(input); i < length; i++) {
var value = input[i];
Expand Down
6 changes: 0 additions & 6 deletions modules/flatten.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import _flatten from './_flatten.js';
import clone from './clone.js';

// Flatten out an array, either recursively (by default), or up to `depth`.
// Passing `true` or `false` as `depth` means `1` or `Infinity`, respectively.
export default function flatten(array, depth) {
if (!depth && depth !== 0) {
depth = Infinity;
} else if (depth <= 0) {
return clone(array);
}
return _flatten(array, depth, false);
}
10 changes: 5 additions & 5 deletions underscore-esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion underscore-esm.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions underscore.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion underscore.js.map

Large diffs are not rendered by default.

0 comments on commit 7d37875

Please sign in to comment.