Skip to content

Instantly share code, notes, and snippets.

@MatthewTrout
Created October 24, 2019 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthewTrout/fd53e8331414b01e723bffade6049a50 to your computer and use it in GitHub Desktop.
Save MatthewTrout/fd53e8331414b01e723bffade6049a50 to your computer and use it in GitHub Desktop.
es6 flatten test
import { flatten } from "./flatten";
test('flatten works', () => {
expect(
flatten(
[1, 2, [3, 4, 5], 6, [7], 8, 9, 10]
)
).toEqual(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
);
});
test('flatten works with multiple levels of nested arrays', () => {
expect(
flatten(
[1, 2, [3, 4, 5], 6, [7, [8, [9]], 10]]
)
).toEqual(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
);
});
test('flatten works with no nesting', () => {
expect(
flatten(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
)
).toEqual(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment