Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

map.js 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var concatMap = require('../');
  2. var test = require('tape');
  3. test('empty or not', function (t) {
  4. var xs = [ 1, 2, 3, 4, 5, 6 ];
  5. var ixes = [];
  6. var ys = concatMap(xs, function (x, ix) {
  7. ixes.push(ix);
  8. return x % 2 ? [ x - 0.1, x, x + 0.1 ] : [];
  9. });
  10. t.same(ys, [ 0.9, 1, 1.1, 2.9, 3, 3.1, 4.9, 5, 5.1 ]);
  11. t.same(ixes, [ 0, 1, 2, 3, 4, 5 ]);
  12. t.end();
  13. });
  14. test('always something', function (t) {
  15. var xs = [ 'a', 'b', 'c', 'd' ];
  16. var ys = concatMap(xs, function (x) {
  17. return x === 'b' ? [ 'B', 'B', 'B' ] : [ x ];
  18. });
  19. t.same(ys, [ 'a', 'B', 'B', 'B', 'c', 'd' ]);
  20. t.end();
  21. });
  22. test('scalars', function (t) {
  23. var xs = [ 'a', 'b', 'c', 'd' ];
  24. var ys = concatMap(xs, function (x) {
  25. return x === 'b' ? [ 'B', 'B', 'B' ] : x;
  26. });
  27. t.same(ys, [ 'a', 'B', 'B', 'B', 'c', 'd' ]);
  28. t.end();
  29. });
  30. test('undefs', function (t) {
  31. var xs = [ 'a', 'b', 'c', 'd' ];
  32. var ys = concatMap(xs, function () {});
  33. t.same(ys, [ undefined, undefined, undefined, undefined ]);
  34. t.end();
  35. });