Skip to content

Commit

Permalink
Merge pull request jashkenas#1228 from JensRantil/document-findWhere
Browse files Browse the repository at this point in the history
`findWhere`: Improved documentation and tests (2nd)
  • Loading branch information
jashkenas committed Jul 25, 2013
2 parents ec42e68 + 02fb2b4 commit e4d66e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ <h2 id="collections">Collection Functions (Arrays or Objects)</h2>
Looks through the <b>list</b> and returns the <i>first</i> value that matches
all of the key-value pairs listed in <b>properties</b>.
</p>
<p>
If no match is found, or if <b>list</b> is empty, <i>undefined</i> will be
returned.
</p>
<pre>
_.findWhere(publicServicePulitzers, {newsroom: "The New York Times"});
=&gt; {year: 1918, newsroom: "The New York Times",
Expand Down
6 changes: 6 additions & 0 deletions test/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ $(document).ready(function() {
deepEqual(result, {a: 1, b: 2});
result = _.findWhere(list, {b: 4});
deepEqual(result, {a: 1, b: 4});

result = _.findWhere(list, {c:1})
ok(_.isUndefined(result), "undefined when not found");

result = _.findWhere([], {c:1});
ok(_.isUndefined(result), "undefined when searching empty list");
});

test('max', function() {
Expand Down

0 comments on commit e4d66e2

Please sign in to comment.