find-streaks
Finds streaks of equal/same item, based on a monotonically increasing "time" property of them.
The following table shows how find-streaks
works with a streak length of 3
.
monotonic
timer bucket output
-------------------------
0 A A starts
1 A
2 B B starts
2 C C starts
5 C A ends
6 B B ends, B starts
end C ends, B ends
Installation
npm install find-streaks
Usage
These items represent the chart above:
const item1 = 0 'a'const item2 = 1 'a'const item3 = 2 'b'const item4 = 2 'c'const item4 = 5 'c'const item5 = 6 'b'
Two items can be part of a streak if they have the same bucket(item)
, which must return a string or null
.
find-streaks
will tell if two items are witin a streak using monotonic(item)
, which must return an integer.
const streakLength = 3const bucket = item1const monotonic = item0
keeping only the last item of each streak
const keepLastOfStreaks = const check flush = // [] // [] // [] // [] // [item2] // [item3] // [item5, item6]
transform stream
as aconst keepLastStream = const keepLast = keepLastkeepLast// …keepLast
callbag operator
as aconst keepLastCallbag = const pipe fromIter forEach = const keepLast =
finding raw starts & ends of streaks
const findStartsEnds = const START END = findStartsEnds const check flush = // ['a', START] // [] // ['b', START] // ['c', START] // ['a', END] // ['b', END, 'b', START] // ['c', END, 'b', END]
Related
lodash.debounce
lodash.throttle
callbag-keep-sequences
– A callbag operator that passes through only sequences with minimum length.flatten-overlapping-ranges
– Flatten overlapping ranges into a sequence of sections.
Contributing
If you have a question or need support using find-streaks
, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use the issues page.