You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
848 B

4 years ago
  1. import _curry2 from "./internal/_curry2.js";
  2. import equals from "./equals.js";
  3. import takeLast from "./takeLast.js";
  4. /**
  5. * Checks if a list ends with the provided sublist.
  6. *
  7. * Similarly, checks if a string ends with the provided substring.
  8. *
  9. * @func
  10. * @memberOf R
  11. * @since v0.24.0
  12. * @category List
  13. * @sig [a] -> [a] -> Boolean
  14. * @sig String -> String -> Boolean
  15. * @param {*} suffix
  16. * @param {*} list
  17. * @return {Boolean}
  18. * @see R.startsWith
  19. * @example
  20. *
  21. * R.endsWith('c', 'abc') //=> true
  22. * R.endsWith('b', 'abc') //=> false
  23. * R.endsWith(['c'], ['a', 'b', 'c']) //=> true
  24. * R.endsWith(['b'], ['a', 'b', 'c']) //=> false
  25. */
  26. var endsWith =
  27. /*#__PURE__*/
  28. _curry2(function (suffix, list) {
  29. return equals(takeLast(suffix.length, list), suffix);
  30. });
  31. export default endsWith;