Skip to content

Commit

Permalink
Revert "Adding _.count to count truthy values in an iterator. _.count…
Browse files Browse the repository at this point in the history
…([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; }) = 3"

This reverts commit c8e3c04.

Conflicts:

	underscore.js
  • Loading branch information
samuelclay committed Apr 6, 2011
1 parent 5457522 commit 1fc7d4b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 34 deletions.
23 changes: 6 additions & 17 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,12 @@ <h2>Table of Contents</h2>
<span class="methods"><a href="#each">each</a>, <a href="#map">map</a>,
<a href="#reduce">reduce</a>, <a href="#reduceRight">reduceRight</a>,
<a href="#detect">detect</a>, <a href="#select">select</a>,
<a href="#reject">reject</a>, <a href="#count">count</a>,
<a href="#all">all</a>, <a href="#any">any</a>,
<a href="#include">include</a>, <a href="#invoke">invoke</a>,
<a href="#pluck">pluck</a>, <a href="#max">max</a>,
<a href="#min">min</a>, <a href="#sortBy">sortBy</a>,
<a href="#sortedIndex">sortedIndex</a>, <a href="#toArray">toArray</a>,
<a href="#size">size</a></span>
<a href="#reject">reject</a>, <a href="#all">all</a>,
<a href="#any">any</a>, <a href="#include">include</a>,
<a href="#invoke">invoke</a>, <a href="#pluck">pluck</a>,
<a href="#max">max</a>, <a href="#min">min</a>,
<a href="#sortBy">sortBy</a>, <a href="#sortedIndex">sortedIndex</a>,
<a href="#toArray">toArray</a>, <a href="#size">size</a></span>
</p>

<p>
Expand Down Expand Up @@ -338,16 +337,6 @@ <h2>Collection Functions (Arrays or Objects)</h2>
<pre>
var odds = _.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
=&gt; [1, 3, 5]
</pre>

<p id="count">
<b class="header">count</b><code>_.count(list, [iterator], [context])</code>
<br />
Returns a count of elements which pass the truth test (<b>iterator</b>).
</p>
<pre>
var count = _.count([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
=&gt; 3
</pre>

<p id="all">
Expand Down
7 changes: 0 additions & 7 deletions test/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@ $(document).ready(function() {
equals(odds.join(', '), '1, 3, 5', 'rejected each even number');
});

test('collections: count', function() {
var count = _.count([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
equals(count, 3, 'counted even numbers');
var count = _.count([0, 1, 2, 3, 4, 5, 6]);
equals(count, 6, 'counted all truthy numbers');
});

test('collections: all', function() {
ok(_.all([]), 'the empty set');
ok(_.all([true, true, true]), 'all true values');
Expand Down
10 changes: 0 additions & 10 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,6 @@
return results;
};

// Returns a count of elements which pass a truth test.
_.count = function(obj, iterator, context) {
var count = 0;
iterator || (iterator = _.identity);
each(obj, function(value, index, list) {
if (iterator.call(context, value, index, list)) count += 1;
});
return count;
};

// Determine whether all of the elements match a truth test.
// Delegates to **ECMAScript 5**'s native `every` if available.
// Aliased as `all`.
Expand Down

0 comments on commit 1fc7d4b

Please sign in to comment.