Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const findPeaks = arr => arr.reduce((result, curr, i) => {
- const prev = arr[i - 1];
- const next = arr.slice(i).find(item => item !== curr);
- if(curr > prev && curr > next) {
- result.pos.push(i);
- result.peaks.push(curr);
- }
- return result;
- }, {
- pos:[],
- peaks:[],
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement