charsRightIndex.js 516 B

1234567891011121314151617
  1. /**
  2. * Used by `_.trim` and `_.trimRight` to get the index of the last character
  3. * of `string` that is not found in `chars`.
  4. *
  5. * @private
  6. * @param {string} string The string to inspect.
  7. * @param {string} chars The characters to find.
  8. * @returns {number} Returns the index of the last character not found in `chars`.
  9. */
  10. function charsRightIndex(string, chars) {
  11. var index = string.length;
  12. while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
  13. return index;
  14. }
  15. module.exports = charsRightIndex;