freecodecamp.cn
freecodecamp.cn copied to clipboard
TypeError: arr.push(...).sort is not a function,why?
Challenge Where do I belong has an issue.
User Agent is: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.22 Safari/537.36 SE 2.X MetaSr 1.0.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
function where(arr, num) {
// Find my place in this sorted array.
arr.push(num).sort(function(a,b){
return a-b;
});
return arr.indexOf(num);
}
where([40, 60], 50);
function where(arr, num) {
arr.push(num);
arr.sort(function(a,b){return a-b;});
return arr.indexOf(num);}
因为数组push方法返回的是更新后的·数组length,并不是数组对象,所以没有sort方法。