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

144 lines
2.9 KiB
Markdown

---
id: a24c1a4622e3c05097f71d67
title: Where do I Belong
challengeType: 1
forumTopicId: 16094
dashedName: where-do-i-belong
---
# --description--
Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted. The returned value should be a number.
For example, `getIndexToIns([1,2,3,4], 1.5)` should return `1` because it is greater than `1` (index 0), but less than `2` (index 1).
Likewise, `getIndexToIns([20,3,5], 19)` should return `2` because once the array has been sorted it will look like `[3,5,20]` and `19` is less than `20` (index 2) and greater than `5` (index 1).
# --hints--
`getIndexToIns([10, 20, 30, 40, 50], 35)` should return a number.
```js
assert.isNumber(getIndexToIns([10, 20, 30, 40, 50], 35));
```
`getIndexToIns([10, 20, 30, 40, 50], 35)` should return `3`.
```js
assert.strictEqual(getIndexToIns([10, 20, 30, 40, 50], 35), 3);
```
`getIndexToIns([10, 20, 30, 40, 50], 30)` should return a number.
```js
assert.isNumber(getIndexToIns([10, 20, 30, 40, 50], 30));
```
`getIndexToIns([10, 20, 30, 40, 50], 30)` should return `2`.
```js
assert.strictEqual(getIndexToIns([10, 20, 30, 40, 50], 30), 2);
```
`getIndexToIns([40, 60], 50)` should return a number.
```js
assert.isNumber(getIndexToIns([40, 60], 50));
```
`getIndexToIns([40, 60], 50)` should return `1`.
```js
assert.strictEqual(getIndexToIns([40, 60], 50), 1);
```
`getIndexToIns([3, 10, 5], 3)` should return a number.
```js
assert.isNumber(getIndexToIns([3, 10, 5], 3));
```
`getIndexToIns([3, 10, 5], 3)` should return `0`.
```js
assert.strictEqual(getIndexToIns([3, 10, 5], 3), 0);
```
`getIndexToIns([5, 3, 20, 3], 5)` should return a number.
```js
assert.isNumber(getIndexToIns([5, 3, 20, 3], 5));
```
`getIndexToIns([5, 3, 20, 3], 5)` should return `2`.
```js
assert.strictEqual(getIndexToIns([5, 3, 20, 3], 5), 2);
```
`getIndexToIns([2, 20, 10], 19)` should return `2`.
```js
assert.strictEqual(getIndexToIns([2, 20, 10], 19), 2);
```
`getIndexToIns([2, 20, 10], 19)` should return a number.
```js
assert.isNumber(getIndexToIns([2, 20, 10], 19));
```
`getIndexToIns([2, 5, 10], 15)` should return `3`.
```js
assert.strictEqual(getIndexToIns([2, 5, 10], 15), 3);
```
`getIndexToIns([2, 5, 10], 15)` should return a number.
```js
assert.isNumber(getIndexToIns([2, 5, 10], 15));
```
`getIndexToIns([], 1)` should return a number.
```js
assert.isNumber(getIndexToIns([], 1));
```
`getIndexToIns([], 1)` should return `0`.
```js
assert.strictEqual(getIndexToIns([], 1), 0);
```
# --seed--
## --seed-contents--
```js
function getIndexToIns(arr, num) {
return num;
}
getIndexToIns([40, 60], 50);
```
# --solutions--
```js
function getIndexToIns(arr, num) {
arr = arr.sort((a, b) => a - b);
for (let i = 0; i < arr.length; i++) {
if (arr[i] >= num) {
return i;
}
}
return arr.length;
}
getIndexToIns([40, 60], 50);
```