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.

42 regels
990 B

4 jaren geleden
  1. import _checkForMethod from "./internal/_checkForMethod.js";
  2. import _curry2 from "./internal/_curry2.js";
  3. /**
  4. * Creates a new list with the separator interposed between elements.
  5. *
  6. * Dispatches to the `intersperse` method of the second argument, if present.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.14.0
  11. * @category List
  12. * @sig a -> [a] -> [a]
  13. * @param {*} separator The element to add to the list.
  14. * @param {Array} list The list to be interposed.
  15. * @return {Array} The new list.
  16. * @example
  17. *
  18. * R.intersperse('a', ['b', 'n', 'n', 's']); //=> ['b', 'a', 'n', 'a', 'n', 'a', 's']
  19. */
  20. var intersperse =
  21. /*#__PURE__*/
  22. _curry2(
  23. /*#__PURE__*/
  24. _checkForMethod('intersperse', function intersperse(separator, list) {
  25. var out = [];
  26. var idx = 0;
  27. var length = list.length;
  28. while (idx < length) {
  29. if (idx === length - 1) {
  30. out.push(list[idx]);
  31. } else {
  32. out.push(list[idx], separator);
  33. }
  34. idx += 1;
  35. }
  36. return out;
  37. }));
  38. export default intersperse;