Add toPairs snippet

This commit is contained in:
Angelos Chalaris
2020-03-23 15:07:23 +02:00
parent edba0e0460
commit 749920ae7f
2 changed files with 40 additions and 0 deletions

17
test/toPairs.test.js Normal file
View File

@ -0,0 +1,17 @@
const {toPairs} = require('./_30s.js');
test('toPairs is a Function', () => {
expect(toPairs).toBeInstanceOf(Function);
});
test('Creates an array of key-value pair arrays from an object.', () => {
expect(toPairs({ a: 1, b: 2 })).toEqual([['a', 1], ['b', 2]]);
});
test('Creates an array of key-value pair arrays from an array.', () => {
expect(toPairs([2, 4, 8])).toEqual([[0, 2], [1, 4], [2, 8]]);
});
test('Creates an array of key-value pair arrays from a string.', () => {
expect(toPairs('shy')).toEqual([['0', 's'], ['1', 'h'], ['2', 'y']]);
});
test('Creates an array of key-value pair arrays from a set.', () => {
expect(toPairs(new Set(['a', 'b', 'c', 'a']))).toEqual([['a', 'a'], ['b', 'b'], ['c', 'c']]);
});