SHARE
TWEET

Untitled

a guest May 21st, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const findPeaks = arr => arr.reduce((result, curr, i) => {
  2.   const prev = arr[i - 1];
  3.   const next = arr.slice(i).find(item => item !== curr);
  4.  
  5.   if(curr > prev && curr > next) {
  6.     result.pos.push(i);
  7.     result.peaks.push(curr);
  8.   }
  9.  
  10.   return result;
  11. }, {
  12.   pos:[],
  13.   peaks:[],
  14. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top