rofrischmann/tokenize-sync

View on GitHub
modules/loopUntilConditionIsFulfilled.js

Summary

Maintainability
A
0 mins
Test Coverage
/* @flow */
export default function loopUntilConditionIsFulfilled(
  end: number,
  condition: Function
) {
  let currentIndex: number = 0

  while (end > currentIndex) {
    if (condition(currentIndex)) {
      return currentIndex
    }

    ++currentIndex
  }

  return end
}