--- id: a24c1a4622e3c05097f71d67 title: Where do I Belong isRequired: true challengeType: 5 videoUrl: '' localeTitle: 我属于哪里? --- ## Description
返回一个值(第二个参数)应该在排序后插入数组(第一个参数)的最低索引。返回的值应该是一个数字。例如, getIndexToIns([1,2,3,4], 1.5)应返回1因为它大于1 (索引0),但小于2 (索引1)。同样, getIndexToIns([20,3,5], 19)应返回2因为一旦数组已经排序,它将看起来像[3,5,20]19小于20 (索引2)并且大于5 (指数1)。如果卡住,请记得使用Read-Search-Ask 。编写自己的代码。
## Instructions
## Tests
```yml tests: - text: 'getIndexToIns([10, 20, 30, 40, 50], 35)应返回3 。' testString: 'assert(getIndexToIns([10, 20, 30, 40, 50], 35) === 3, "getIndexToIns([10, 20, 30, 40, 50], 35) should return 3.");' - text: 'getIndexToIns([10, 20, 30, 40, 50], 35)应返回一个数字。' testString: 'assert(typeof(getIndexToIns([10, 20, 30, 40, 50], 35)) === "number", "getIndexToIns([10, 20, 30, 40, 50], 35) should return a number.");' - text: 'getIndexToIns([10, 20, 30, 40, 50], 30)应该返回2 。' testString: 'assert(getIndexToIns([10, 20, 30, 40, 50], 30) === 2, "getIndexToIns([10, 20, 30, 40, 50], 30) should return 2.");' - text: 'getIndexToIns([10, 20, 30, 40, 50], 30)应该返回一个数字。' testString: 'assert(typeof(getIndexToIns([10, 20, 30, 40, 50], 30)) === "number", "getIndexToIns([10, 20, 30, 40, 50], 30) should return a number.");' - text: 'getIndexToIns([40, 60], 50)应返回1 。' testString: 'assert(getIndexToIns([40, 60], 50) === 1, "getIndexToIns([40, 60], 50) should return 1.");' - text: 'getIndexToIns([40, 60], 50)应返回一个数字。' testString: 'assert(typeof(getIndexToIns([40, 60], 50)) === "number", "getIndexToIns([40, 60], 50) should return a number.");' - text: 'getIndexToIns([3, 10, 5], 3)应该返回0 。' testString: 'assert(getIndexToIns([3, 10, 5], 3) === 0, "getIndexToIns([3, 10, 5], 3) should return 0.");' - text: 'getIndexToIns([3, 10, 5], 3)应返回一个数字。' testString: 'assert(typeof(getIndexToIns([3, 10, 5], 3)) === "number", "getIndexToIns([3, 10, 5], 3) should return a number.");' - text: 'getIndexToIns([5, 3, 20, 3], 5)应返回2 。' testString: 'assert(getIndexToIns([5, 3, 20, 3], 5) === 2, "getIndexToIns([5, 3, 20, 3], 5) should return 2.");' - text: 'getIndexToIns([5, 3, 20, 3], 5)应返回一个数字。' testString: 'assert(typeof(getIndexToIns([5, 3, 20, 3], 5)) === "number", "getIndexToIns([5, 3, 20, 3], 5) should return a number.");' - text: 'getIndexToIns([2, 20, 10], 19)应该返回2 。' testString: 'assert(getIndexToIns([2, 20, 10], 19) === 2, "getIndexToIns([2, 20, 10], 19) should return 2.");' - text: 'getIndexToIns([2, 20, 10], 19)应返回一个数字。' testString: 'assert(typeof(getIndexToIns([2, 20, 10], 19)) === "number", "getIndexToIns([2, 20, 10], 19) should return a number.");' - text: 'getIndexToIns([2, 5, 10], 15)应该返回3 。' testString: 'assert(getIndexToIns([2, 5, 10], 15) === 3, "getIndexToIns([2, 5, 10], 15) should return 3.");' - text: 'getIndexToIns([2, 5, 10], 15)应返回一个数字。' testString: 'assert(typeof(getIndexToIns([2, 5, 10], 15)) === "number", "getIndexToIns([2, 5, 10], 15) should return a number.");' - text: 'getIndexToIns([], 1)应该返回0 。' testString: 'assert(getIndexToIns([], 1) === 0, "getIndexToIns([], 1) should return 0.");' - text: 'getIndexToIns([], 1)应该返回一个数字。' testString: 'assert(typeof(getIndexToIns([], 1)) === "number", "getIndexToIns([], 1) should return a number.");' ```
## Challenge Seed
```js function getIndexToIns(arr, num) { // Find my place in this sorted array. return num; } getIndexToIns([40, 60], 50); ```
## Solution
```js // solution required ```