Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.2 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6994cff2290543b3aec9f511 Challenge 212: Array Insertion 28 challenge-212

--description--

Given an array, a value to insert into the array, and an index to insert the value at, return a new array with the value inserted at the specified index.

--hints--

insertIntoArray([2, 4, 8, 10], 6, 2) should return [2, 4, 6, 8, 10].

assert.deepEqual(insertIntoArray([2, 4, 8, 10], 6, 2), [2, 4, 6, 8, 10]);

insertIntoArray(["the", "quick", "fox"], "brown", 2) should return ["the", "quick", "brown", "fox"].

assert.deepEqual(insertIntoArray(["the", "quick", "fox"], "brown", 2), ["the", "quick", "brown", "fox"]);

insertIntoArray([], 0, 0) should return [0].

assert.deepEqual(insertIntoArray([], 0, 0), [0]);

insertIntoArray([0, 1, 1, 2, 3, 8, 13], 5, 5) should return [0, 1, 1, 2, 3, 5, 8, 13].

assert.deepEqual(insertIntoArray([0, 1, 1, 2, 3, 8, 13], 5, 5), [0, 1, 1, 2, 3, 5, 8, 13]);

--seed--

--seed-contents--

function insertIntoArray(arr, value, index) {

  return arr;
}

--solutions--

function insertIntoArray(arr, value, index) {
  return [
    ...arr.slice(0, index),
    value,
    ...arr.slice(index)
  ];
}