Find Streak
In an array, find the N consecutive items whose combined value is highest. Or lowest.
Installation
npm install findstreak
Syntax
array findStreak(array source, int length, function reducer[, boolean lowest])
source
: array to look streaks fromlength
: number of elements included in the streakreducer
: function used to reduce values in thesource
array to an integer, uses Array.reduce() syntaxlowest
: look for lowest values instead of highest
Examples:
Simply get streak of three highest numbers:
const findStreak = ;let arr = 0 1 2 3 4 5 4 3 2 1 0;let n = 3;let a + b;let newArr = ; // [4, 5, 4]
Get streaks of highest and lowest item values:
const findStreak = ;let arr = time: '00:00' value: 7 time: '01:00' value: 3 time: '02:00' value: 1 time: '03:00' value: 9 time: '04:00' value: 5 time: '05:00' value: 4 time: '06:00' value: 2 time: '07:00' value: 3;let a + bvalue; let highestTree = ;console;// [{"time":"03:00","value":9},{"time":"04:00","value":5},{"time":"05:00","value":4}] let highestFour = ;console;// [{"time":"00:00","value":7},{"time":"01:00","value":3},{"time":"02:00","value":1},{"time":"03:00","value":9}] let lowestTwo = ;console;// [{"time":"01:00","value":3},{"time":"02:00","value":1}] let lowestThree = ;console;// [{"time":"05:00","value":4},{"time":"06:00","value":2,{"time":"07:00","value":3}]