es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
16 lines (14 loc) • 397 B
JavaScript
function at(arr, indices) {
const result = new Array(indices.length);
const length = arr.length;
for (let i = 0; i < indices.length; i++) {
let index = indices[i];
index = Number.isInteger(index) ? index : Math.trunc(index) || 0;
if (index < 0) {
index += length;
}
result[i] = arr[index];
}
return result;
}
export { at };