Libraryless. Click here for Pure Java version (167L/2K).
1 | static double digitalVariation(int[] array) {
|
2 | int n = l(array); |
3 | if (n == 0) ret 0; // ? - undefined |
4 | if (n == 1) ret 0; |
5 | var value = array[0]; |
6 | int deviations = 0; |
7 | for (int i = 1; i < n; i++) |
8 | if (array[i] != value) |
9 | ++deviations; |
10 | ret doubleRatio(deviations, n); |
11 | } |
12 | |
13 | static <A> double digitalVariation(Iterable<A> l) {
|
14 | var it = iterator(l); |
15 | if (!it.hasNext()) ret 0; // ? - undefined |
16 | int n = 1; |
17 | var value = it.next(); |
18 | int deviations = 0; |
19 | while (it.hasNext()) {
|
20 | ++n; |
21 | if (!eq(value, it.hasNext())) |
22 | ++deviations; |
23 | } |
24 | ret doubleRatio(deviations, n); |
25 | } |
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1035489 |
| Snippet name: | digitalVariation |
| Eternal ID of this version: | #1035489/3 |
| Text MD5: | 48b71e224a024f49a4bf50f7cc68fdf1 |
| Transpilation MD5: | f9f27a2387d40cfdba88d36af9cb0b57 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-05-27 00:36:48 |
| Source code size: | 617 bytes / 25 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 372 / 465 |
| Version history: | 2 change(s) |
| Referenced in: | [show references] |