Skip to content

Commit

Permalink
🔧 use existing relative-indexing-method example
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekNonGeneric committed Jan 5, 2021
1 parent 6ceaa8c commit ad2f46f
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions _data/stage3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,11 @@
A proposal to add a <code>.at()</code> method to all the basic indexable
classes (<code>Array</code>, <code>String</code>, <code>TypedArray</code>).
example: |-
function at(n) {
&#x9;// ToInteger() abstract op
&#x9;n = Math.trunc(n) || 0;
&#x9;// Allow negative indexing from the end
&#x9;if(n &#x3C; 0) n += this.length;
&#x9;// OOB access is guaranteed to return undefined
&#x9;if(n &#x3C; 0 || n &#x3E;= this.length) return undefined;
&#x9;// Otherwise, this is just normal property access
&#x9;return this[n];
}
// Other TypedArray constructors omitted for brevity.
for (let C of [Array, String, Uint8Array]) {
Object.defineProperty(C.prototype, &#x22;at&#x22;,
{ value: at,
writable: true,
enumerable: false,
configurable: true });
}
var list = [&#x22;apple&#x22;, &#x22;orange&#x22;, &#x22;banana&#x22;];
list.at(-1) // banana, using negative index
list.at(0) // apple
list.at(1) // orange
list.at(2) // banana
has_specification: true
presented:
- date: "November\_2020"
Expand Down

0 comments on commit ad2f46f

Please sign in to comment.