-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
第 161 题:用最精炼的代码实现数组非零非负最小值 index #582
Comments
const arr = [10, 21, 0, -7, 35, 7, 9, 23, 18]; arr.reduce((pre,cur,index)=>{ |
const ary = [10, 21, 0, -7, 35, 7, 9, 23, 18];
function getIndex(ary) {
const result = ary.reduce(
(acc, cur, index) =>
acc.value > cur && cur > 0 ? { value: cur, index } : acc,
{ value: Infinity, index: -1 }
);
return result.index;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: