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.

62 lines
1.1 KiB

4 years ago
  1. concat-map
  2. ==========
  3. Concatenative mapdashery.
  4. [![browser support](http://ci.testling.com/substack/node-concat-map.png)](http://ci.testling.com/substack/node-concat-map)
  5. [![build status](https://secure.travis-ci.org/substack/node-concat-map.png)](http://travis-ci.org/substack/node-concat-map)
  6. example
  7. =======
  8. ``` js
  9. var concatMap = require('concat-map');
  10. var xs = [ 1, 2, 3, 4, 5, 6 ];
  11. var ys = concatMap(xs, function (x) {
  12. return x % 2 ? [ x - 0.1, x, x + 0.1 ] : [];
  13. });
  14. console.dir(ys);
  15. ```
  16. ***
  17. ```
  18. [ 0.9, 1, 1.1, 2.9, 3, 3.1, 4.9, 5, 5.1 ]
  19. ```
  20. methods
  21. =======
  22. ``` js
  23. var concatMap = require('concat-map')
  24. ```
  25. concatMap(xs, fn)
  26. -----------------
  27. Return an array of concatenated elements by calling `fn(x, i)` for each element
  28. `x` and each index `i` in the array `xs`.
  29. When `fn(x, i)` returns an array, its result will be concatenated with the
  30. result array. If `fn(x, i)` returns anything else, that value will be pushed
  31. onto the end of the result array.
  32. install
  33. =======
  34. With [npm](http://npmjs.org) do:
  35. ```
  36. npm install concat-map
  37. ```
  38. license
  39. =======
  40. MIT
  41. notes
  42. =====
  43. This module was written while sitting high above the ground in a tree.