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.5 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6994cff2290543b3aec9f511 Challenge 212: Array Insertion 29 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--

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

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(insert_into_array([2, 4, 8, 10], 6, 2), [2, 4, 6, 8, 10])`)
}})

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

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(insert_into_array(["the", "quick", "fox"], "brown", 2), ["the", "quick", "brown", "fox"])`)
}})

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

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(insert_into_array([], 0, 0), [0])`)
}})

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

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(insert_into_array([0, 1, 1, 2, 3, 8, 13], 5, 5), [0, 1, 1, 2, 3, 5, 8, 13])`)
}})

--seed--

--seed-contents--

def insert_into_array(arr, value, index):

    return arr

--solutions--

def insert_into_array(arr, value, index):
    return arr[:index] + [value] + arr[index:]