We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
const arr = [10, 21, 0, -7, 35, 7, 9, 23, 18]; function getIndex(arr) { let min = Infinity; arr.forEach((v) => { v > 0 && v < min && (min = v); }); return arr.indexOf(min); } console.log(getIndex(arr));
The text was updated successfully, but these errors were encountered:
const arr = [10, 21, 0, -7, 35, 7, 9, 23, 18];
arr.reduce((pre,cur,index)=>{ return cur>0&cur<pre.val ? {i:index,val:cur} : pre },{i:-1,val:Infinity})
Sorry, something went wrong.
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; }
const min = arr..sort((a,b) => a-b).filter(n => n > 0)[0]
No branches or pull requests
The text was updated successfully, but these errors were encountered: