Comparing version 0.0.2 to 0.1.0
54
index.js
@@ -8,6 +8,7 @@ /** | ||
const _weaveArray = a => { | ||
const z = []; | ||
const n2 = Math.ceil(a.length / 2); | ||
const a1 = a.slice(0, n2); | ||
const a2 = a.slice(n2); | ||
const z = []; | ||
let c = 0; | ||
@@ -42,18 +43,2 @@ while (c++ < n2) { | ||
/** | ||
* Perform actual weave | ||
* @param s - Incoming string | ||
* @returns {string} - Result of the weave | ||
* @private | ||
*/ | ||
const _weaveString = s => _weaveArray(s.split('')).join(''); | ||
/** | ||
* Perform actual unweave | ||
* @param s | ||
* @returns {string} | ||
* @private | ||
*/ | ||
const _unweaveString = s => _unweaveArray(s.split('')).join(''); | ||
/** | ||
* Perform weave, handling some outlier cases | ||
@@ -66,3 +51,3 @@ * @param s - Incoming string | ||
return _weaveString(s); | ||
return _weaveArray(s.split('')).join(''); | ||
}; | ||
@@ -78,10 +63,39 @@ | ||
return _unweaveString(s); | ||
return _unweaveArray(s.split('')).join(''); | ||
}; | ||
/** | ||
* Weave array | ||
* @param a | ||
* @returns {*} | ||
*/ | ||
const weaveArray = a => { | ||
if (a.length < 3) return a; | ||
return _weaveArray(a); | ||
}; | ||
/** | ||
* Unweave array | ||
* @param a | ||
* @returns {*} | ||
*/ | ||
const unweaveArray = a => { | ||
if (a.length < 3) return a; | ||
return _unweaveArray(a); | ||
}; | ||
module.exports = { | ||
// String based functions | ||
shuffle: weave, | ||
unshuffle: unweave, | ||
weave, | ||
unshuffle: unweave, | ||
unweave, | ||
// Array based functions | ||
shuffleArray: weaveArray, | ||
unshuffleArray: unweaveArray, | ||
weaveArray: weaveArray, | ||
unweaveArray: unweaveArray, | ||
}; |
{ | ||
"name": "faro", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Faro out-shuffle a string", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const assert = require('assert'); | ||
const faro = require('../index'); | ||
const { shuffle, weave, unshuffle, unweave } = faro; | ||
const { shuffle, weave, unshuffle, unweave, shuffleArray, weaveArray, unshuffleArray, unweaveArray } = faro; | ||
@@ -100,1 +100,11 @@ describe('Weave', () => { | ||
}); | ||
describe('Weave-Array', () => { | ||
describe('Empty array', () => { | ||
it('should return empty array when input is empty array', () => { | ||
assert.equal(weaveArray([]) instanceof Array, true); | ||
assert.equal(weaveArray([]).length, 0); | ||
}) | ||
}); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6376
179