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

23
LINES

< > BotCompany Repo | #1031899 // linearlyShortenArray

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

Libraryless. Click here for Pure Java version (3027L/17K).

1  
static double[] linearlyShortenArray(double[] a, int newLength) {
2  
  int l = l(a);
3  
  if (newLength == l) ret a;
4  
  double[] b = new[newLength];
5  
  double x = 0, step = doubleRatio(newLength, l);
6  
  for i to newLength: {
7  
    b[i] = a[iround(x)];
8  
    x += step;
9  
  }
10  
  ret b;
11  
}
12  
13  
static short[] linearlyShortenArray(short[] a, int newLength) {
14  
  int l = l(a);
15  
  if (newLength == l) ret a;
16  
  short[] b = new[newLength];
17  
  double x = 0, step = doubleRatio(newLength, l);
18  
  for i to newLength: {
19  
    b[i] = a[iround(x)];
20  
    x += step;
21  
  }
22  
  ret b;
23  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1031899
Snippet name: linearlyShortenArray
Eternal ID of this version: #1031899/2
Text MD5: f5676ca6fafc50d3cb49adc89350225d
Transpilation MD5: f05c94fefe8f1624944c4d893b4898f3
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-07-24 06:50:10
Source code size: 561 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 191 / 282
Version history: 1 change(s)
Referenced in: [show references]