From d75bdd9805fc3920dbc3aabd4911c19e9a74c6cf Mon Sep 17 00:00:00 2001 From: King Date: Mon, 12 Feb 2018 16:38:13 -0500 Subject: [PATCH] ran npm run tester and test files generated --- test/permuteAll/permuteAll.js | 31 ++++++++++++++++++++++++++++++ test/permuteAll/permuteAll.test.js | 13 +++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 test/permuteAll/permuteAll.js create mode 100644 test/permuteAll/permuteAll.test.js diff --git a/test/permuteAll/permuteAll.js b/test/permuteAll/permuteAll.js new file mode 100644 index 000000000..f005c1bd8 --- /dev/null +++ b/test/permuteAll/permuteAll.js @@ -0,0 +1,31 @@ +const permuteAll = (input) => { +const result = []; +let inputState = input; + +if (typeof input === 'string') { +inputState = input.split(''); +} else if (typeof input === 'number') { +inputState = (input).toString().split(''); +} + +const permute = (arr, m = []) => { +if (arr.length === 0) { +result.push(m) +} else { +for (let i = 0; i < arr.length; i++) { +let curr = arr.slice(); +let next = curr.splice(i, 1); +permute(curr.slice(), m.concat(next)) +} +} +} + +permute(inputState); + +return (typeof input === 'string') +? result.map(variant => variant.join('')) +: (typeof input === 'number') +? result.map(variant => parseFloat(variant.join(''))) +: result; +} +module.exports = permuteAll; \ No newline at end of file diff --git a/test/permuteAll/permuteAll.test.js b/test/permuteAll/permuteAll.test.js new file mode 100644 index 000000000..540321748 --- /dev/null +++ b/test/permuteAll/permuteAll.test.js @@ -0,0 +1,13 @@ +const test = require('tape'); +const permuteAll = require('./permuteAll.js'); + +test('Testing permuteAll', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof permuteAll === 'function', 'permuteAll is a Function'); + //t.deepEqual(permuteAll(args..), 'Expected'); + //t.equal(permuteAll(args..), 'Expected'); + //t.false(permuteAll(args..), 'Expected'); + //t.throws(permuteAll(args..), 'Expected'); + t.end(); +}); \ No newline at end of file