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
66 lines
1.5 KiB
Markdown
66 lines
1.5 KiB
Markdown
---
|
|
id: 6994cff2290543b3aec9f511
|
|
title: "Challenge 212: Array Insertion"
|
|
challengeType: 29
|
|
dashedName: 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]`.
|
|
|
|
```js
|
|
({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"]`.
|
|
|
|
```js
|
|
({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]`.
|
|
|
|
```js
|
|
({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]`.
|
|
|
|
```js
|
|
({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--
|
|
|
|
```py
|
|
def insert_into_array(arr, value, index):
|
|
|
|
return arr
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```py
|
|
def insert_into_array(arr, value, index):
|
|
return arr[:index] + [value] + arr[index:]
|
|
```
|