Skip to content

Commit

Permalink
♻️ finished closes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Mar 23, 2023
1 parent ffcf833 commit 2e5f540
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ export function incrementOrInit(hash, key) {

/**
*
* @param {*} hashOrSet a hash composed preferably of strings.
* @param {*} arrayOrSet an composed preferably of strings or a Set.
* @returns a "saco" or bag that counts the number of repeated elements
*/
export function hashify(hashOrSet) {
export function hashify(arrayOrSet) {
const initialHash = {};
return hashOrSet.reduce(
const pureArray =
arrayOrSet instanceof Set ? Array.from(arrayOrSet) : arrayOrSet;
return pureArray.reduce(
(runningHash, el) => incrementOrInit(runningHash, el),
initialHash
);
Expand Down
1 change: 1 addition & 0 deletions test/node/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const anArray = [..."aaa".split(""), ..."bbb".split("")];
const aSaco = hashify(anArray);
test("hashifyTest", (_) => {
deepEqual(aSaco, { a: 3, b: 3 });
deepEqual(hashify(new Set(["a", "b"])), { a: 1, b: 1 });
});

const anotherArray = [..."ccc".split(""), ..."bbb".split("")];
Expand Down

0 comments on commit 2e5f540

Please sign in to comment.