Count occurrences of values within a range.
No future updates are planned. Feel free to continue using it, but expect no support.
This is a package for the command-line JSON processor jq
. Install the package in your jq project/package directory with jqnpm
:
jqnpm install joelpurra/jq-counter-buckets
import "joelpurra/jq-counter-buckets" as CounterBuckets;
# Create counter buckets, increment their counters, add two together.
CounterBuckets::create(10) # [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
| CounterBuckets::increment(4) # [ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
| CounterBuckets::increment(0) # [ 1, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
| CounterBuckets::increment(9) # [ 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
| CounterBuckets::increment(9) # [ 1, 0, 0, 0, 1, 0, 0, 0, 0, 2 ]
| CounterBuckets::increment(5; 99) # [ 1, 0, 0, 0, 1, 99, 0, 0, 0, 2 ]
| . as $first
| CounterBuckets::create(10) # [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
| CounterBuckets::increment(3; 10) # [ 0, 0, 0, 10, 0, 0, 0, 0, 0, 0 ]
| CounterBuckets::increment(4) # [ 0, 0, 0, 10, 1, 0, 0, 0, 0, 0 ]
| CounterBuckets::increment(5) # [ 0, 0, 0, 10, 1, 1, 0, 0, 0, 0 ]
| . as $second
| $first
| CounterBuckets::addition($second) # [1, 0, 0,10,2,100, 0, 0, 0,2]
| . as $combined
| {
first: $first,
second: $second,
combined: $combined
}
Copyright (c) 2015 Joel Purra https://joelpurra.com/ All rights reserved.
When using jq-counter-buckets, comply to the MIT license. Please see the LICENSE file for details.