Skip to content

Commit

Permalink
Update syntax blocks for TypedArray pages (mdn#4677)
Browse files Browse the repository at this point in the history
* Update syntax blocks for TypedArray pages

* Address feedback

* Use accumulator instead of previousValue
  • Loading branch information
Elchi3 authored May 5, 2021
1 parent 8db916a commit 93edb0e
Show file tree
Hide file tree
Showing 30 changed files with 334 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<h2 id="Syntax">Syntax</h2>

<pre class="brush: js"><var>arr</var>[Symbol.iterator]()</pre>
<pre class="brush: js">[Symbol.iterator]()</pre>

<h3 id="Return_value">Return value</h3>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">var <var>item</var> = typedArr.at(index)</pre>
<pre class="brush: js">at(index)</pre>

<h3 id="Parameters">Parameters</h3>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@

<h2 id="Syntax">Syntax</h2>

<pre
class="brush: js"><code><var>typedarray</var>.copyWithin(<var>target</var>, <var>start</var>[, <var>end</var> = this.length])</code></pre>
<pre class="brush: js">
copyWithin(target, start)
copyWithin(target, start, end)
</pre>

<h3 id="Parameters">Parameters</h3>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<h2 id="Syntax">Syntax</h2>

<pre class="brush: js"><var>arr</var>.entries()</pre>
<pre class="brush: js">entries()</pre>

<h3 id="Return_value">Return value</h3>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,27 @@

<h2 id="Syntax">Syntax</h2>

<pre
class="brush: js"><var>typedarray</var>.every(<var>callback</var>[, <var>thisArg</var>])</pre>
<pre class="brush: js">
// Arrow function
every((element) => { ... } )
every((element, index) => { ... } )
every((element, index, array) => { ... } )

// Callback function
every(callbackFn)
every(callbackFn, thisArg)

// Inline callback function
every(function callbackFn(element) { ... })
every(function callbackFn(element, index) { ... })
every(function callbackFn(element, index, array){ ... })
every(function callbackFn(element, index, array) { ... }, thisArg)
</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
<dt><code><var>callback</var></code></dt>
<dt><code><var>callbackFn</var></code></dt>
<dd>A function to test for each element, taking three arguments:
<dl>
<dt><code><var>element</var></code></dt>
Expand All @@ -42,7 +56,7 @@ <h3 id="Parameters">Parameters</h3>
</dl>
</dd>
<dt><code><var>thisArg</var></code> {{Optional_inline}}</dt>
<dd>A value to use as <code>this</code> when executing <code><var>callback</var></code>.
<dd>A value to use as <code>this</code> when executing <code><var>callbackFn</var></code>.
</dd>
</dl>

Expand All @@ -53,20 +67,20 @@ <h3 id="Return_value">Return value</h3>

<h2 id="Description">Description</h2>

<p>The <code>every</code> method executes the provided <code><var>callback</var></code>
<p>The <code>every</code> method executes the provided <code><var>callbackFn</var></code>
function once for each element present in the typed array until it finds the one where
<code><var>callback</var></code> returns a falsy{{Glossary("falsy")}} value. If such an
<code><var>callbackFn</var></code> returns a {{Glossary("falsy")}} value. If such an
element is found, the <code>every</code> method immediately returns <code>false</code>.
Otherwise, if <code><var>callback</var></code> returns a {{Glossary("truthy")}} value
Otherwise, if <code><var>callbackFn</var></code> returns a {{Glossary("truthy")}} value
for all elements, <code>every</code> returns <code>true</code>.</p>

<p><code><var>callback</var></code> is invoked with three arguments: the value of the
<p><code><var>callbackFn</var></code> is invoked with three arguments: the value of the
element, the index of the element, and the typed array object being traversed.</p>

<p>If a <code><var>thisArg</var></code> parameter is provided to <code>every</code>, it
will be used as callback's <code>this</code> value. Otherwise, the value
<code>undefined</code> will be used as its <code>this</code> value. The
<code>this</code> value ultimately observable by <code><var>callback</var></code> is
<code>this</code> value ultimately observable by <code><var>callbackFn</var></code> is
determined according to <a
href="/en-US/docs/Web/JavaScript/Reference/Operators/this">the usual rules for
determining the <code>this</code> seen by a function</a>.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@

<h2 id="Syntax">Syntax</h2>

<pre
class="brush: js"><var>typedarray</var>.fill(<var>value</var>[, <var>start = 0</var>[, <var>end = this.length</var>]])</pre>
<pre class="brush: js">
fill(value)
fill(value, start)
fill(value, start, end)
</pre>

<h3 id="Parameters">Parameters</h3>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,32 @@

<h2 id="Syntax">Syntax</h2>

<pre
class="brush: js"><var>typedarray</var>.filter(<var>callback</var>[, <var>thisArg</var>])</pre>
<pre class="brush: js">
// Arrow function
filter((element) => { ... } )
filter((element, index) => { ... } )
filter((element, index, array) => { ... } )

// Callback function
filter(callbackFn)
filter(callbackFn, thisArg)

// Inline callback function
filter(function callbackFn(element) { ... })
filter(function callbackFn(element, index) { ... })
filter(function callbackFn(element, index, array){ ... })
filter(function callbackFn(element, index, array) { ... }, thisArg)
</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
<dt><code><var>callback</var></code></dt>
<dt><code><var>callbackFn</var></code></dt>
<dd>Function to test each element of the typed array. Invoked with arguments
<code>(<var>element</var>, <var>index</var>, <var>typedarray</var>)</code>. Return
<code>(<var>element</var>, <var>index</var>, <var>array</var>)</code>. Return
<code>true</code> to keep the element, <code>false</code> otherwise.</dd>
<dt><code><var>thisArg</var></code>{{optional_inline}}</dt>
<dd>Value to use as <code>this</code> when executing <code><var>callback</var></code>.
<dd>Value to use as <code>this</code> when executing <code><var>callbackFn</var></code>.
</dd>
</dl>

Expand All @@ -45,17 +59,17 @@ <h3 id="Return_value">Return value</h3>

<h2 id="Description">Description</h2>

<p>The <code>filter()</code> method calls a provided <code><var>callback</var></code>
<p>The <code>filter()</code> method calls a provided <code><var>callbackFn</var></code>
function once for each element in a typed array, and constructs a new typed array of all
the values for which <code><var>callback</var></code> returns <a
the values for which <code><var>callbackFn</var></code> returns <a
href="/en-US/docs/Glossary/Truthy">a value that coerces to <code>true</code></a>.
<code><var>callback</var></code> is invoked only for indexes of the typed array which
<code><var>callbackFn</var></code> is invoked only for indexes of the typed array which
have assigned values; it is not invoked for indexes which have been deleted or which
have never been assigned values. Typed array elements which do not pass the
<code><var>callback</var></code> test are skipped, and are not included in the new typed
<code><var>callbackFn</var></code> test are skipped, and are not included in the new typed
array.</p>

<p><code><var>callback</var></code> is invoked with three arguments:</p>
<p><code><var>callbackFn</var></code> is invoked with three arguments:</p>

<ol>
<li>the value of the element</li>
Expand All @@ -64,20 +78,20 @@ <h2 id="Description">Description</h2>
</ol>

<p>If a <code><var>thisArg</var></code> parameter is provided to <code>filter()</code>, it
will be passed to <code><var>callback</var></code> when invoked, for use as its
will be passed to <code><var>callbackFn</var></code> when invoked, for use as its
<code>this</code> value. Otherwise, the value <code>undefined</code> will be passed for
use as its <code>this</code> value. The <code>this</code> value ultimately observable by
<code><var>callback</var></code> is determined according to <a
<code><var>callbackFn</var></code> is determined according to <a
href="/en-US/docs/Web/JavaScript/Reference/Operators/this">the usual rules for
determining the <code>this</code> seen by a function</a>.</p>

<p><code>filter()</code> does not mutate the typed array on which it is called.</p>

<p>The range of elements processed by <code>filter()</code> is set before the first
invocation of <code><var>callback</var></code>. Elements which are appended to the typed
invocation of <code><var>callbackFn</var></code>. Elements which are appended to the typed
array after the call to <code>filter()</code> begins will not be visited by
<code><var>callback</var></code>. If existing elements of the typed array are changed,
or deleted, their value as passed to <code><var>callback</var></code> will be the value
<code><var>callbackFn</var></code>. If existing elements of the typed array are changed,
or deleted, their value as passed to <code><var>callbackFn</var></code> will be the value
at the time <code>filter()</code> visits them; elements that are deleted are not
visited.</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,27 @@

<h2 id="Syntax">Syntax</h2>

<pre
class="brush: js"><var>typedarray</var>.find(<var>callback</var>[, <var>thisArg</var>])</pre>
<pre class="brush: js">
// Arrow function
find((element) => { ... } )
find((element, index) => { ... } )
find((element, index, array) => { ... } )

// Callback function
find(callbackFn)
find(callbackFn, thisArg)

// Inline callback function
find(function callbackFn(element) { ... })
find(function callbackFn(element, index) { ... })
find(function callbackFn(element, index, array){ ... })
find(function callbackFn(element, index, array) { ... }, thisArg)
</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
<dt><code><var>callback</var></code></dt>
<dt><code><var>callbackFn</var></code></dt>
<dd>Function to execute on each value in the typed array, taking three arguments:
<dl>
<dt><code><var>element</var></code></dt>
Expand All @@ -46,7 +60,7 @@ <h3 id="Parameters">Parameters</h3>
</dl>
</dd>
<dt><code><var>thisArg</var></code> {{optional_inline}}</dt>
<dd>Object to use as <code>this</code> when executing <code><var>callback</var></code>.
<dd>Object to use as <code>this</code> when executing <code><var>callbackFn</var></code>.
</dd>
</dl>

Expand All @@ -57,31 +71,31 @@ <h3 id="Return_value">Return value</h3>

<h2 id="Description">Description</h2>

<p>The <code>find()</code> method executes the <code><var>callback</var></code> function
<p>The <code>find()</code> method executes the <code><var>callbackFn</var></code> function
once for each element present in the typed array until it finds one where
<code><var>callback</var></code> returns a true value. If such an element is found,
<code><var>callbackFn</var></code> returns a true value. If such an element is found,
<code>find()</code> immediately returns the value of that element. Otherwise,
<code>find()</code> returns {{jsxref("undefined")}}. <code><var>callback</var></code> is
<code>find()</code> returns {{jsxref("undefined")}}. <code><var>callbackFn</var></code> is
invoked only for indexes of the typed array which have assigned values; it is not
invoked for indexes which have been deleted or which have never been assigned values.
</p>

<p><code><var>callback</var></code> is invoked with three arguments: the value of the
<p><code><var>callbackFn</var></code> is invoked with three arguments: the value of the
element, the index of the element, and the typed array object being traversed.</p>

<p>If a <code><var>thisArg</var></code> parameter is provided to <code>find()</code>, it
will be used as the <code>this</code> for each invocation of the
<code><var>callback</var></code>. If it is not provided, then {{jsxref("undefined")}} is
<code><var>callbackFn</var></code>. If it is not provided, then {{jsxref("undefined")}} is
used.</p>

<p><code>find()</code> does not mutate the typed array on which it is called.</p>

<p>The range of elements processed by <code>find()</code> is set before the first
invocation of <code><var>callback</var></code>. Elements that are appended to the typed
invocation of <code><var>callbackFn</var></code>. Elements that are appended to the typed
array after the call to <code>find()</code> begins will not be visited by
<code><var>callback</var></code>. If an existing, unvisited element of the typed array
is changed by <code><var>callback</var></code>, its value passed to the visiting
<code><var>callback</var></code> will be the value at the time that <code>find()</code>
<code><var>callbackFn</var></code>. If an existing, unvisited element of the typed array
is changed by <code><var>callbackFn</var></code>, its value passed to the visiting
<code><var>callbackFn</var></code> will be the value at the time that <code>find()</code>
visits that element's index; elements that are deleted are not visited.</p>

<h2 id="Examples">Examples</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,27 @@

<h2 id="Syntax">Syntax</h2>

<pre
class="brush: js"><var>typedarray</var>.findIndex(<var>callback</var>[, <var>thisArg</var>])</pre>
<pre class="brush: js">
// Arrow function
findIndex((element) => { ... } )
findIndex((element, index) => { ... } )
findIndex((element, index, array) => { ... } )

// Callback function
findIndex(callbackFn)
findIndex(callbackFn, thisArg)

// Inline callback function
findIndex(function callbackFn(element) { ... })
findIndex(function callbackFn(element, index) { ... })
findIndex(function callbackFn(element, index, array){ ... })
findIndex(function callbackFn(element, index, array) { ... }, thisArg)
</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
<dt><code><var>callback</var></code></dt>
<dt><code><var>callbackFn</var></code></dt>
<dd>Function to execute on each value in the typed array, taking three arguments:
<dl>
<dt><code><var>element</var></code></dt>
Expand All @@ -43,7 +57,7 @@ <h3 id="Parameters">Parameters</h3>
</dl>
</dd>
<dt><code><var>thisArg</var></code> {{optional_inline}}</dt>
<dd>Object to use as <code>this</code> when executing <code><var>callback</var></code>.
<dd>Object to use as <code>this</code> when executing <code><var>callbackFn</var></code>.
</dd>
</dl>

Expand All @@ -53,15 +67,15 @@ <h3 id="Return_value">Return value</h3>

<h2 id="Description">Description</h2>

<p>The <code>findIndex()</code> method executes the <code><var>callback</var></code>
<p>The <code>findIndex()</code> method executes the <code><var>callbackFn</var></code>
function once for each element present in the typed array until it finds one where
<code><var>callback</var></code> returns a true value. If such an element is found,
<code><var>callbackFn</var></code> returns a true value. If such an element is found,
<code>findIndex()</code> immediately returns the index of that element. Otherwise,
<code>findIndex()</code> returns -1. <code><var>callback</var></code> is invoked only
<code>findIndex()</code> returns -1. <code><var>callbackFn</var></code> is invoked only
for indexes of the typed array which have assigned values; it is not invoked for indexes
which have been deleted or which have never been assigned values.</p>

<p><code><var>callback</var></code> is invoked with three arguments: the value of the
<p><code><var>callbackFn</var></code> is invoked with three arguments: the value of the
element, the index of the element, and the typed array object being traversed.</p>

<p>If a <code><var>thisArg</var></code> parameter is provided to <code>findIndex()</code>,
Expand All @@ -72,11 +86,11 @@ <h2 id="Description">Description</h2>
<p><code>findIndex()</code> does not mutate the typed array on which it is called.</p>

<p>The range of elements processed by <code>findIndex()</code> is set before the first
invocation of <code><var>callback</var></code>. Elements that are appended to the typed
invocation of <code><var>callbackFn</var></code>. Elements that are appended to the typed
array after the call to <code>findIndex()</code> begins will not be visited by
<code><var>callback</var></code>. If an existing, unvisited element of the typed array
is changed by <code><var>callback</var></code>, its value passed to the visiting
<code><var>callback</var></code> will be the value at the time that
<code><var>callbackFn</var></code>. If an existing, unvisited element of the typed array
is changed by <code><var>callbackFn</var></code>, its value passed to the visiting
<code><var>callbackFn</var></code> will be the value at the time that
<code>findIndex()</code> visits that element's index; elements that are deleted are not
visited.</p>

Expand Down
Loading

0 comments on commit 93edb0e

Please sign in to comment.