Skip to content

Commit

Permalink
Rename to filterReject (#18)
Browse files Browse the repository at this point in the history
* Change to filterReject

* Update index.html

* Update spec.emu
  • Loading branch information
jridgewell authored Jul 8, 2021
1 parent 290acab commit 3bb33a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# proposal-array-filtering

A proposal to add `Array.prototype.filterOut`.
A proposal to add `Array.prototype.filterReject`.

```js
const array = [1, 2, 3, 4, 5];

// filter keeps the items that return true.
array.filter(i => (i < 3)); // => [1, 2];

// filterOut removes the items that return true.
array.filterOut(i => (i < 3)); // => [3, 4, 5];
// filterReject removes the items that return true.
array.filterReject(i => (i < 3)); // => [3, 4, 5];
```

## Champions
Expand Down
20 changes: 10 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<link rel="stylesheet" href="./spec.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<script src="./spec.js"></script>
<title>Array Filtering</title><script type="application/json" id="menu-search-biblio">[{"type":"clause","id":"sec-scope","aoid":null,"title":"Scope","titleHTML":"Scope","number":"1","namespace":"https://tc39.es/proposal-array-filtering/","location":"","referencingIds":[],"key":"Scope"},{"type":"clause","id":"sec-array.prototype.filterOut","aoid":null,"title":"Array.prototype.filterOut ( callbackfn [ , thisArg ] )","titleHTML":"Array.prototype.filterOut ( <var>callbackfn</var> [ , <var>thisArg</var> ] )","number":"2.1","namespace":"https://tc39.es/proposal-array-filtering/","location":"","referencingIds":[],"key":"Array.prototype.filterOut ( callbackfn [ , thisArg ] )"},{"type":"clause","id":"sec-array.prototype.groupby","aoid":null,"title":"Array.prototype.groupBy ( callbackfn [ , thisArg ] )","titleHTML":"Array.prototype.groupBy ( <var>callbackfn</var> [ , <var>thisArg</var> ] )","number":"2.2","namespace":"https://tc39.es/proposal-array-filtering/","location":"","referencingIds":[],"key":"Array.prototype.groupBy ( callbackfn [ , thisArg ] )"},{"type":"clause","id":"sec-properties-of-the-array-prototype-object","aoid":null,"title":"Properties of the Array Prototype Object (22.1.3)","titleHTML":"Properties of the Array Prototype Object (<a href=\"https://tc39.es/ecma262/#sec-properties-of-the-array-prototype-object\">22.1.3</a>)","number":"2","namespace":"https://tc39.es/proposal-array-filtering/","location":"","referencingIds":[],"key":"Properties of the Array Prototype Object (22.1.3)"},{"type":"clause","id":"sec-copyright-and-software-license","aoid":null,"title":"Copyright & Software License","titleHTML":"Copyright &amp; Software License","number":"A","namespace":"https://tc39.es/proposal-array-filtering/","location":"","referencingIds":[],"key":"Copyright & Software License"}]</script><script>"use strict";
<title>Array Filtering</title><script type="application/json" id="menu-search-biblio">[{"type":"clause","id":"sec-scope","aoid":null,"title":"Scope","titleHTML":"Scope","number":"1","namespace":"https://tc39.es/proposal-array-filtering/","location":"","referencingIds":[],"key":"Scope"},{"type":"clause","id":"sec-array.prototype.filterReject","aoid":null,"title":"Array.prototype.filterReject ( callbackfn [ , thisArg ] )","titleHTML":"Array.prototype.filterReject ( <var>callbackfn</var> [ , <var>thisArg</var> ] )","number":"2.1","namespace":"https://tc39.es/proposal-array-filtering/","location":"","referencingIds":[],"key":"Array.prototype.filterReject ( callbackfn [ , thisArg ] )"},{"type":"clause","id":"sec-array.prototype.groupby","aoid":null,"title":"Array.prototype.groupBy ( callbackfn [ , thisArg ] )","titleHTML":"Array.prototype.groupBy ( <var>callbackfn</var> [ , <var>thisArg</var> ] )","number":"2.2","namespace":"https://tc39.es/proposal-array-filtering/","location":"","referencingIds":[],"key":"Array.prototype.groupBy ( callbackfn [ , thisArg ] )"},{"type":"clause","id":"sec-properties-of-the-array-prototype-object","aoid":null,"title":"Properties of the Array Prototype Object (22.1.3)","titleHTML":"Properties of the Array Prototype Object (<a href=\"https://tc39.es/ecma262/#sec-properties-of-the-array-prototype-object\">22.1.3</a>)","number":"2","namespace":"https://tc39.es/proposal-array-filtering/","location":"","referencingIds":[],"key":"Properties of the Array Prototype Object (22.1.3)"},{"type":"clause","id":"sec-copyright-and-software-license","aoid":null,"title":"Copyright & Software License","titleHTML":"Copyright &amp; Software License","number":"A","namespace":"https://tc39.es/proposal-array-filtering/","location":"","referencingIds":[],"key":"Copyright & Software License"}]</script><script>"use strict";

function Search(menu) {
this.menu = menu;
Expand Down Expand Up @@ -1845,7 +1845,7 @@
display: none;
}
}
</style></head><body><div id="menu-toggle">☰</div><div id="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-scope" title="Scope"><span class="secnum">1</span> Scope</a></li><li><span class="item-toggle">◢</span><a href="#sec-properties-of-the-array-prototype-object" title="Properties of the Array Prototype Object (22.1.3)"><span class="secnum">2</span> Properties of the Array Prototype Object (</a><a href="https://tc39.es/ecma262/#sec-properties-of-the-array-prototype-object">22.1.3</a>)<ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-array.prototype.filterOut" title="Array.prototype.filterOut ( callbackfn [ , thisArg ] )"><span class="secnum">2.1</span> Array.prototype.filterOut ( <var>callbackfn</var> [ , <var>thisArg</var> ] )</a></li><li><span class="item-toggle-none"></span><a href="#sec-array.prototype.groupby" title="Array.prototype.groupBy ( callbackfn [ , thisArg ] )"><span class="secnum">2.2</span> Array.prototype.groupBy ( <var>callbackfn</var> [ , <var>thisArg</var> ] )</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright &amp; Software License"><span class="secnum">A</span> Copyright &amp; Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version first">Stage 1 Draft / July 7, 2021</h1><h1 class="title">Array Filtering</h1>
</style></head><body><div id="menu-toggle">☰</div><div id="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-scope" title="Scope"><span class="secnum">1</span> Scope</a></li><li><span class="item-toggle">◢</span><a href="#sec-properties-of-the-array-prototype-object" title="Properties of the Array Prototype Object (22.1.3)"><span class="secnum">2</span> Properties of the Array Prototype Object (</a><a href="https://tc39.es/ecma262/#sec-properties-of-the-array-prototype-object">22.1.3</a>)<ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-array.prototype.filterReject" title="Array.prototype.filterReject ( callbackfn [ , thisArg ] )"><span class="secnum">2.1</span> Array.prototype.filterReject ( <var>callbackfn</var> [ , <var>thisArg</var> ] )</a></li><li><span class="item-toggle-none"></span><a href="#sec-array.prototype.groupby" title="Array.prototype.groupBy ( callbackfn [ , thisArg ] )"><span class="secnum">2.2</span> Array.prototype.groupBy ( <var>callbackfn</var> [ , <var>thisArg</var> ] )</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright &amp; Software License"><span class="secnum">A</span> Copyright &amp; Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version first">Stage 1 Draft / July 7, 2021</h1><h1 class="title">Array Filtering</h1>
<emu-clause id="sec-scope">
<h1><span class="secnum">1</span> Scope</h1>
Expand All @@ -1858,19 +1858,19 @@ <h1><span class="secnum">1</span> Scope</h1>
<h1><span class="secnum">2</span> Properties of the Array Prototype Object (<a href="https://tc39.es/ecma262/#sec-properties-of-the-array-prototype-object">22.1.3</a>)</h1>
<ins class="block">
<emu-clause id="sec-array.prototype.filterOut">
<h1><span class="secnum">2.1</span> Array.prototype.filterOut ( <var>callbackfn</var> [ , <var>thisArg</var> ] )</h1>
<emu-clause id="sec-array.prototype.filterReject">
<h1><span class="secnum">2.1</span> Array.prototype.filterReject ( <var>callbackfn</var> [ , <var>thisArg</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p><var>callbackfn</var> should be a function that accepts three arguments and returns a value that is coercible to the Boolean value <emu-val>true</emu-val> or <emu-val>false</emu-val>. <code>filterOut</code> calls <var>callbackfn</var> once for each element in the array, in ascending order, and constructs a new array of all the values for which <var>callbackfn</var> returns <emu-val>false</emu-val>. <var>callbackfn</var> is called only for elements of the array which actually exist; it is not called for missing elements of the array.</p>
<p><var>callbackfn</var> should be a function that accepts three arguments and returns a value that is coercible to the Boolean value <emu-val>true</emu-val> or <emu-val>false</emu-val>. <code>filterReject</code> calls <var>callbackfn</var> once for each element in the array, in ascending order, and constructs a new array of all the values for which <var>callbackfn</var> returns <emu-val>false</emu-val>. <var>callbackfn</var> is called only for elements of the array which actually exist; it is not called for missing elements of the array.</p>
<p>If a <var>thisArg</var> parameter is provided, it will be used as the <emu-val>this</emu-val> value for each invocation of <var>callbackfn</var>. If it is not provided, <emu-val>undefined</emu-val> is used instead.</p>
<p><var>callbackfn</var> is called with three arguments: the value of the element, the index of the element, and the object being traversed.</p>
<p><code>filterOut</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callbackfn</var>.</p>
<p>The range of elements processed by <code>filterOut</code> is set before the first call to <var>callbackfn</var>. Elements which are appended to the array after the call to <code>filterOut</code> begins will not be visited by <var>callbackfn</var>. If existing elements of the array are changed their value as passed to <var>callbackfn</var> will be the value at the time <code>filterOut</code> visits them; elements that are deleted after the call to <code>filterOut</code> begins and before being visited are not visited.</p>
<p><code>filterReject</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callbackfn</var>.</p>
<p>The range of elements processed by <code>filterReject</code> is set before the first call to <var>callbackfn</var>. Elements which are appended to the array after the call to <code>filterReject</code> begins will not be visited by <var>callbackfn</var>. If existing elements of the array are changed their value as passed to <var>callbackfn</var> will be the value at the time <code>filterReject</code> visits them; elements that are deleted after the call to <code>filterReject</code> begins and before being visited are not visited.</p>
</div></emu-note>
<p>When the <code>filterOut</code> method is called with one or two arguments, the following steps are taken:</p>
<p>When the <code>filterReject</code> method is called with one or two arguments, the following steps are taken:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_0"><a href="https://tc39.es/ecma262/#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_1"><a href="https://tc39.es/ecma262/#sec-lengthofarraylike">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_2"><a href="https://tc39.es/ecma262/#sec-iscallable">IsCallable</a></emu-xref>(<var>callbackfn</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArraySpeciesCreate" id="_ref_3"><a href="https://tc39.es/ecma262/#sec-arrayspeciescreate">ArraySpeciesCreate</a></emu-xref>(<var>O</var>, 0).</li><li>Let <var>k</var> be 0.</li><li>Let <var>to</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var><ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_4"><a href="https://tc39.es/ecma262/#sec-tostring">ToString</a></emu-xref>(<var>k</var>).</li><li>Let <var>kPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_5"><a href="https://tc39.es/ecma262/#sec-hasproperty">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_6"><a href="https://tc39.es/ecma262/#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>rejected</var> be !&nbsp;<emu-xref aoid="ToBoolean" id="_ref_7"><a href="https://tc39.es/ecma262/#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_8"><a href="https://tc39.es/ecma262/#sec-call">Call</a></emu-xref>(<var>callbackfn</var>, <var>thisArg</var>, « <var>kValue</var>, <var>k</var>, <var>O</var> »)).</li><li>If <var>rejected</var> is <emu-val>false</emu-val>, then<ol><li>Perform ?&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_9"><a href="https://tc39.es/ecma262/#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_10"><a href="https://tc39.es/ecma262/#sec-tostring">ToString</a></emu-xref>(<var>to</var>), <var>kValue</var>).</li><li>Set <var>to</var> to <var>to</var> + 1.</li></ol></li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>The <code>filterOut</code> function is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
<p>The <code>filterReject</code> function is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
</ins>
Expand Down Expand Up @@ -1912,4 +1912,4 @@ <h2>Software License</h2>
<p>THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>
</emu-annex>
</div></body>
</div></body>
14 changes: 7 additions & 7 deletions spec.emu
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ location: https://tc39.es/proposal-array-filtering/
<h1>Properties of the Array Prototype Object (<a href="https://tc39.es/ecma262/#sec-properties-of-the-array-prototype-object">22.1.3</a>)</h1>

<ins class="block">
<emu-clause id="sec-array.prototype.filterOut">
<h1>Array.prototype.filterOut ( _callbackfn_ [ , _thisArg_ ] )</h1>
<emu-clause id="sec-array.prototype.filterReject">
<h1>Array.prototype.filterReject ( _callbackfn_ [ , _thisArg_ ] )</h1>
<emu-note>
<p>_callbackfn_ should be a function that accepts three arguments and returns a value that is coercible to the Boolean value *true* or *false*. `filterOut` calls _callbackfn_ once for each element in the array, in ascending order, and constructs a new array of all the values for which _callbackfn_ returns *false*. _callbackfn_ is called only for elements of the array which actually exist; it is not called for missing elements of the array.</p>
<p>_callbackfn_ should be a function that accepts three arguments and returns a value that is coercible to the Boolean value *true* or *false*. `filterReject` calls _callbackfn_ once for each element in the array, in ascending order, and constructs a new array of all the values for which _callbackfn_ returns *false*. _callbackfn_ is called only for elements of the array which actually exist; it is not called for missing elements of the array.</p>
<p>If a _thisArg_ parameter is provided, it will be used as the *this* value for each invocation of _callbackfn_. If it is not provided, *undefined* is used instead.</p>
<p>_callbackfn_ is called with three arguments: the value of the element, the index of the element, and the object being traversed.</p>
<p>`filterOut` does not directly mutate the object on which it is called but the object may be mutated by the calls to _callbackfn_.</p>
<p>The range of elements processed by `filterOut` is set before the first call to _callbackfn_. Elements which are appended to the array after the call to `filterOut` begins will not be visited by _callbackfn_. If existing elements of the array are changed their value as passed to _callbackfn_ will be the value at the time `filterOut` visits them; elements that are deleted after the call to `filterOut` begins and before being visited are not visited.</p>
<p>`filterReject` does not directly mutate the object on which it is called but the object may be mutated by the calls to _callbackfn_.</p>
<p>The range of elements processed by `filterReject` is set before the first call to _callbackfn_. Elements which are appended to the array after the call to `filterReject` begins will not be visited by _callbackfn_. If existing elements of the array are changed their value as passed to _callbackfn_ will be the value at the time `filterReject` visits them; elements that are deleted after the call to `filterReject` begins and before being visited are not visited.</p>
</emu-note>
<p>When the `filterOut` method is called with one or two arguments, the following steps are taken:</p>
<p>When the `filterReject` method is called with one or two arguments, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be ? ToObject(*this* value).
1. Let _len_ be ? LengthOfArrayLike(_O_).
Expand All @@ -52,7 +52,7 @@ location: https://tc39.es/proposal-array-filtering/
1. Return _A_.
</emu-alg>
<emu-note>
<p>The `filterOut` function is intentionally generic; it does not require that its *this* value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
<p>The `filterReject` function is intentionally generic; it does not require that its *this* value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</emu-note>
</emu-clause>
</ins>
Expand Down

0 comments on commit 3bb33a8

Please sign in to comment.