美文网首页
#267 Where do I belong

#267 Where do I belong

作者: Kaier5 | 来源:发表于2017-02-13 15:29 被阅读0次
  • push(); 在原数组的末尾增加一个元素,并返回新的数组长度(Array.length)

  • sort(function(a,b){return a-b;});:按照数字大小升序排列;

答案:
function where(arr, num) {
    arr.push(num);
   return arr.sort(function(a,b){return a-b;}).indexOf(num);
}

where([40, 60], 50);

相关文章

网友评论

      本文标题:#267 Where do I belong

      本文链接:https://www.haomeiwen.com/subject/oyqzittx.html