-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fixes #349: add _.partition function #1430
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,6 +233,7 @@ | |
<li>- <a href="#compact">compact</a></li> | ||
<li>- <a href="#flatten">flatten</a></li> | ||
<li>- <a href="#without">without</a></li> | ||
<li>- <a href="#partition">partition</a></li> | ||
<li>- <a href="#union">union</a></li> | ||
<li>- <a href="#intersection">intersection</a></li> | ||
<li>- <a href="#difference">difference</a></li> | ||
|
@@ -432,7 +433,7 @@ <h2 id="collections">Collection Functions (Arrays or Objects)</h2> | |
array-like objects such as</i> <tt>arguments</tt>, <tt>NodeList</tt><i> | ||
and similar. But it works by duck-typing, so avoid passing objects with | ||
a numeric <tt>length</tt> property. It's also good to note that an | ||
<tt>each</tt> loop cannot be broken out of — to break, use <b>_.find</b> | ||
<tt>each</tt> loop cannot be broken out of — to break, use <b>_.find</b> | ||
instead. | ||
</i> | ||
</p> | ||
|
@@ -841,6 +842,17 @@ <h2 id="arrays">Array Functions</h2> | |
<pre> | ||
_.without([1, 2, 1, 0, 3, 1, 4], 0, 1); | ||
=> [2, 3, 4] | ||
</pre> | ||
|
||
<p id="partition"> | ||
<b class="header">partition</b><code>_.partition(array, predicate)</code> | ||
<br /> | ||
Split <b>array</b> into two arrays: one whose elements all satisfy | ||
<b>predicate</b>, and one whose elements all do not satisfy <b>predicate</b>. | ||
</p> | ||
<pre> | ||
_.partition([0, 1, 2, 3, 4, 5], function(e) { return isOdd(e); }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason this isn't simply _.partition([0, 1, 2, 3, 4, 5], isOdd); ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hah, yeah we can do that. I had simplified an earlier version that included the parity test implementation, but didn't notice that it could be simplified more. Will update with commit SHA. edit: 678900b |
||
=> [[1, 3, 5], [0, 2, 4]] | ||
</pre> | ||
|
||
<p id="union"> | ||
|
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.
Is it okay to use "predicate" now? The documentation doesn't currently use this term, though it should: "iterator" is both vague and slightly misleading.
I'd like to open a pull request to replace "iterator" with "predicate" where appropriate (in the code as well as the documentation). Would such a pull request be considered?
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.
Oh, I just used what was natural to me. I'd +1 such a PR.
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.
Yes, that would be a great change.
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.
#1435