FreeCodeCampChina / FreeCodeCampChina/freecodecamp.cn

Where do I belong

Open
#623 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
CSS
Stars
37.8k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

Challenge [Where do I belong](https://freecodecamp.cn/challenges/where-do-i-belong#?solution=function%20where(arr%2C%20num)%20%7B%0A%09%2F%2F%20%E8%AF%B7%E6%8A%8A%E4%BD%A0%E7%9A%84%E4%BB%A3%E7%A0%81%E5%86%99%E5%9C%A8%E8%BF%99%E9%87%8C%0A%09var%20array%20%3D%20Array.from(arr)%3B%0A%09if%20(array.indexOf(num)%20%3D%3D%3D%20-1)%0A%09%09array.push(num)%3B%0A%09array.sort(function%20(a%2C%20b)%20%7B%0A%09%09return%20a%20%3E%20b%3B%0A%09%7D)%3B%0A%09%0A%09return%20array.indexOf(num)%3B%0A%7D%0A%0Awhere(%5B10%2C%2020%2C%2030%2C%2040%2C%2050%5D%2C%2035)%3B%0A%2F%2Fwhere(%5B10%2C%2020%2C%2030%2C%2040%2C%2050%5D%2C%2030)%3B%0A) has an issue.
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:
```javascript
function where(arr, num) {
// 请把你的代码写在这里
var array = Array.from(arr);
if (array.indexOf(num) === -1)
array.push(num);
array.sort(function (a, b) {
return a > b;
});

return array.indexOf(num);
}

where([10, 20, 30, 40, 50], 35);
//where([10, 20, 30, 40, 50], 30);

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.