|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
397 bytes
|
| Line | |
|---|
| 1 | function at(arr, indices) {
|
|---|
| 2 | const result = new Array(indices.length);
|
|---|
| 3 | const length = arr.length;
|
|---|
| 4 | for (let i = 0; i < indices.length; i++) {
|
|---|
| 5 | let index = indices[i];
|
|---|
| 6 | index = Number.isInteger(index) ? index : Math.trunc(index) || 0;
|
|---|
| 7 | if (index < 0) {
|
|---|
| 8 | index += length;
|
|---|
| 9 | }
|
|---|
| 10 | result[i] = arr[index];
|
|---|
| 11 | }
|
|---|
| 12 | return result;
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | export { at };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.