Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

13
LINES

< > BotCompany Repo | #1025236 // localMaxima - note: does not find a maximum when there is a plateau

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (127L/1K).

1  
static L<Int> localMaxima(L<Double> l) {
2  
  ret localMaxima(toDoubleArray(l));
3  
}
4  
5  
static L<Int> localMaxima(double[] l) {
6  
  new L<Int> out;
7  
  int n = l(l);
8  
  for i to n:
9  
    if ((i == 0 || l[i] > l[i-1])
10  
      && (i == n-1 || l[i] > l[i+1]))
11  
      out.add(i);
12  
  ret out;
13  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025236
Snippet name: localMaxima - note: does not find a maximum when there is a plateau
Eternal ID of this version: #1025236/3
Text MD5: 37ba76d19e8a57d17b08fa116cd830b7
Transpilation MD5: ecb2c061ab22590f599b38f70753dead
Author: stefan
Category: javax / maths
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-28 20:29:06
Source code size: 283 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 217 / 317
Version history: 2 change(s)
Referenced in: [show references]