本文正在参与掘金团队号上线活动,点击 查看大厂春招职位
一、题目描述:
用最精炼的代码实现数组非零非负最小值index
// 例如:[10,21,0,-7,35,7,9,23,18] 输出5, 7最小
function getIndex(arr){
let index=null;
...
return index;
}
二、思路分析:
我的思路是找到数组排序后的最小值,再用findIndex方法找到下标。
三、AC 代码:
Object.prototype.map = function (handleFn) {
return Object.keys(this).reduce((newObj, key) => {
return newObj[key] = handleFn(this[key], key, this);
}, {})
}
四、总结:
试着参加掘金活动打个卡;