-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added support for variable-depth flatten #1961
Conversation
I forgot to save a file so I'm closing and re-submitting this. |
You can force-push your branch instead of closing this one. |
Done. Didn't know you could do that. |
Could you remove the |
I'm pretty sure you should not commit the dist/ and doc/ folders. I'm guessing the common case is that people want it to be flattened only by one level, and would use flattenDeep otherwise. I'd argue it would actually make more sense to have the maxDepth option in flattenDeep function (then put that one in the 2-args mapping, and flatten in the 1 or keep it uncapped). |
result || (result = []); | ||
|
||
if (maxDepth < 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The min depth should be 1
. A flatten that doesn't flatten isn't a flatten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally made it callable with maxDepth == 0
for flexibility purposes. It defaults to 1. I'll change it if you think it's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya it shouldn't go below 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't look too closely, but is the case needed for recursion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not, since it won't be called recursively once maxDepth
reaches 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't look too closely, but is the case needed for recursion?
Naw just base functionality flatten should flatten at least 1 level.
I've expected a depth level request for a while :P
9f359c8
to
9975b89
Compare
If the consensus is that I should move this functionality to |
I think that a separate method is the way to go. I like I like the modification to Have you signed our cla? |
I just signed it (submitted a CLA on 2016-02-09). If this will be a separate method, what do you think of the name |
No the "By" postfix has another meaning. I think |
Okay, What should it do if a depth of However, I concede that |
Okaaaay, it's gross but consistent to do a simple |
|
I like
So turning in to |
ed13a72
to
f3aa305
Compare
I've moved the new functionality into a separate Please verify that I am defaulting the |
@@ -27,6 +27,7 @@ | |||
|
|||
/** Used as a reference to the global object. */ | |||
var root = (typeof global == 'object' && global) || this; | |||
debugger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rogue debugger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! Should have noticed that.
At one point, I had a bug where baseFlatten
was defaulting depth
to 0
instead of 1
(because toInteger(undefined)
behaved differently than I assumed), and the test suite wouldn't even load.
New commit fixes those three things. |
function baseFlatten(array, isDeep, isStrict, result) { | ||
function baseFlatten(array, depth, isStrict, result) { | ||
depth = depth === undefined ? 1 : depth; | ||
if (depth < 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move the depth < 1
and copyArray()
bit to flattenDepth
.
Added support for variable-depth flatten.
Thank you @msmorgan! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This commit adds an optional
maxDepth
argument to_.flatten
, allowing a nested array to be recursively flattened to a variable degree.Please double-check I made the correct change in fp/_mapping.js, because it was hard to tell what was going on in that file.