Libraryless. Click here for Pure Java version (3027L/17K).
static double[] linearlyShortenArray(double[] a, int newLength) { int l = l(a); if (newLength == l) ret a; double[] b = new[newLength]; double x = 0, step = doubleRatio(newLength, l); for i to newLength: { b[i] = a[iround(x)]; x += step; } ret b; } static short[] linearlyShortenArray(short[] a, int newLength) { int l = l(a); if (newLength == l) ret a; short[] b = new[newLength]; double x = 0, step = doubleRatio(newLength, l); for i to newLength: { b[i] = a[iround(x)]; x += step; } ret b; }
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: | 400 / 530 |
| Version history: | 1 change(s) |
| Referenced in: | [show references] |