Sha256: 05818dc978962f55a321262bdb4b13074db8c55a10830217acd0c581f923136b

Contents?: true

Size: 679 Bytes

Versions: 24

Compression:

Stored size: 679 Bytes

Contents

'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
}

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
trusty-cms-6.3.1 node_modules/longest-streak/index.js
trusty-cms-5.0.7 node_modules/longest-streak/index.js
trusty-cms-5.0.6 node_modules/longest-streak/index.js
trusty-cms-5.0.5 node_modules/longest-streak/index.js
trusty-cms-5.0.4 node_modules/longest-streak/index.js
trusty-cms-5.0.3 node_modules/longest-streak/index.js
trusty-cms-5.0.2 node_modules/longest-streak/index.js
trusty-cms-5.0.1 node_modules/longest-streak/index.js
trusty-cms-4.3.5 node_modules/longest-streak/index.js
trusty-cms-5.0.0 node_modules/longest-streak/index.js
trusty-cms-4.3.4 node_modules/longest-streak/index.js
trusty-cms-4.3.3 node_modules/longest-streak/index.js
trusty-cms-4.3.2 node_modules/longest-streak/index.js
trusty-cms-4.3.1 node_modules/longest-streak/index.js
trusty-cms-4.3 node_modules/longest-streak/index.js
trusty-cms-4.2.3 node_modules/longest-streak/index.js
trusty-cms-4.2.2 node_modules/longest-streak/index.js
trusty-cms-4.2.1 node_modules/longest-streak/index.js
trusty-cms-4.2 node_modules/longest-streak/index.js
trusty-cms-4.1.9 node_modules/longest-streak/index.js