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