kata排名第一的答案
function findUniq(arr)
{
//sort:数组排序函数 更改原数组 传入一个函数
- 若 a 小于 b,在排序后的数组中 a 应该出现在 b 之前,则返回一个小于 0 的值。
- 若 a 等于 b,则返回 0。
- 若 a 大于 b,则返回一个大于 0 的值。
arr.sort((a,b)=>a-b);//按照从小到大排序
return arr[0]==arr[1]? arr.pop():arr[0]
//arr.pop()删除最后一名数组并返回删除的值
//如果排第一的值等于第二的值则证明正确答案在最后返回最后的值 反之第一个是正确答案
}