This repository has been archived on 2020-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
TripSit_Suite/node_modules/longest-streak/index.js

37 lines
679 B
JavaScript

'use strict'
module.exports = longestStreak
// Get the count of the longest repeating streak of `character` in `value`.
function longestStreak(value, character) {
var count = 0
var maximum = 0
var expected
var index
if (typeof character !== 'string' || character.length !== 1) {
throw new Error('Expected character')
}
value = String(value)
index = value.indexOf(character)
expected = index
while (index !== -1) {
count++
if (index === expected) {
if (count > maximum) {
maximum = count
}
} else {
count = 1
}
expected = index + 1
index = value.indexOf(character, expected)
}
return maximum
}