Skip to content

Commit

Permalink
ran deno fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Boyko committed Mar 13, 2021
1 parent c9635a6 commit f018845
Show file tree
Hide file tree
Showing 60 changed files with 662 additions and 596 deletions.
789 changes: 416 additions & 373 deletions README.MD

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions src/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Rhum.testPlan("array/*", () => {
() => {
Rhum.asserts.assertEquals(
partition(["beep", "boop", "foo", "bar"], [true, true, false, true]),
[["beep", "boop", "bar"], ["foo"]]
[["beep", "boop", "bar"], ["foo"]],
);
}
},
);
});
Rhum.testSuite("partitionBy()", () => {
Expand All @@ -56,9 +56,9 @@ Rhum.testPlan("array/*", () => {
"foo",
"bar",
]),
[["beep", "boop", "bar"], ["foo"]]
[["beep", "boop", "bar"], ["foo"]],
);
}
},
);
});
Rhum.testSuite("cartesianProduct()", () => {
Expand All @@ -71,7 +71,7 @@ Rhum.testPlan("array/*", () => {
["y", 1],
["y", 2],
]);
}
},
);
});
});
Expand Down Expand Up @@ -193,12 +193,12 @@ Rhum.testSuite("differenceWith()", () => {
const actual1 = differenceWith<any & { x: any }>(
(obj1, obj2) => obj1.x === obj2.x,
objects,
[{ x: 1, y: 2 }]
[{ x: 1, y: 2 }],
);
const actual2 = differenceWith<any & { y: any }>(
(obj1, obj2) => obj1.y === obj2.y,
objects,
[{ x: 3, y: 2 }]
[{ x: 3, y: 2 }],
);

Rhum.asserts.assertEquals(actual1, [{ x: 2, y: 1 }]);
Expand All @@ -215,9 +215,9 @@ Rhum.testSuite("dropWhile()", () => {
const testArr = [1, 2, 3, 4, 3, 2, 1];
Rhum.asserts.assertEquals(
dropWhile(testArr, (x) => x < 3),
[3, 4, 3, 2, 1]
[3, 4, 3, 2, 1],
);
}
},
);
});
Rhum.testSuite("dropWhileRight()", () => {
Expand All @@ -227,17 +227,17 @@ Rhum.testSuite("dropWhileRight()", () => {
const testArr = [1, 2, 3, 4, 3, 2, 1];
Rhum.asserts.assertEquals(
dropWhileRight(testArr, (x) => x < 3),
[1, 2, 3, 4, 3]
[1, 2, 3, 4, 3],
);
}
},
);
});
Rhum.testSuite("findLastIndex()", () => {
Rhum.testCase("should find the last index that matches", () => {
const testArr = [1, 2, 3, 4, 3, 2, 1];
Rhum.asserts.assertEquals(
findLastIndex(testArr, (x: number) => x === 3),
4
4,
);
});
});
Expand Down Expand Up @@ -270,7 +270,7 @@ Rhum.testSuite("fromPairs()", () => {
["b", 2],
];
Rhum.asserts.assertEquals(fromPairs(testArr), { a: 1, b: 2 });
}
},
);
});
Rhum.testSuite("intersection()", () => {
Expand All @@ -282,7 +282,7 @@ Rhum.testSuite("intersection()", () => {
[2, 3],
];
Rhum.asserts.assertEquals(intersection(...testArrs), [2]);
}
},
);
});
Rhum.testSuite("intersectionBy()", () => {
Expand All @@ -291,7 +291,7 @@ Rhum.testSuite("intersectionBy()", () => {
() => {
Rhum.asserts.assertEquals(
intersectionBy(Math.floor, [2.1, 1.2], [2.3, 3.4]),
[2.1]
[2.1],
);
Rhum.asserts.assertEquals(
intersectionBy(
Expand All @@ -300,11 +300,11 @@ Rhum.testSuite("intersectionBy()", () => {
[
{ x: 2, y: 7 },
{ x: 1, y: 35 },
]
],
),
[{ x: 1, y: 7 }]
[{ x: 1, y: 7 }],
);
}
},
);
});
Rhum.testSuite("intersectionWith()", () => {
Expand All @@ -323,11 +323,11 @@ Rhum.testSuite("intersectionWith()", () => {
intersectionWith(
(a, b) => JSON.stringify(a) === JSON.stringify(b),
objects,
others
others,
),
[{ x: 1, y: 2 }]
[{ x: 1, y: 2 }],
);
}
},
);
});
Rhum.testSuite("zip()", () => {
Expand Down Expand Up @@ -360,15 +360,15 @@ Rhum.testSuite("shank", () => {
]);
Rhum.asserts.assertEquals(namesNoBravo, ["alpha", "charlie"]);
Rhum.asserts.assertEquals(names, ["alpha", "bravo", "charlie"]);
}
},
);
});
Rhum.testSuite("union()", () => {
Rhum.testCase(
"Creates an array of unique values, in order, from all given arrays",
() => {
Rhum.asserts.assertEquals(union([2, 1, 3], [4, 3, 7]), [2, 1, 3, 4, 7]);
}
},
);
});
Rhum.testSuite("unionBy()", () => {
Expand All @@ -387,14 +387,14 @@ Rhum.testSuite("unionBy()", () => {
{ x: 2, y: 9 },
{ x: 1, y: 30 },
{ x: 2, y: 44 },
]
],
),
[
{ x: 1, y: 7 },
{ x: 2, y: 9 },
]
],
);
}
},
);
});
Rhum.testSuite("unionWith()", () => {
Expand All @@ -413,15 +413,15 @@ Rhum.testSuite("unionWith()", () => {
unionWith(
(a, b) => JSON.stringify(a) === JSON.stringify(b),
objects,
others
others,
),
[
{ x: 1, y: 2 },
{ x: 2, y: 1 },
{ x: 1, y: 1 },
]
],
);
}
},
);
});
Rhum.testSuite("uniq()", () => {
Expand All @@ -443,9 +443,9 @@ Rhum.testSuite("uniqBy()", () => {
{ x: 2 },
{ x: 1 },
]),
[{ x: 1 }, { x: 2 }]
[{ x: 1 }, { x: 2 }],
);
}
},
);
});
Rhum.testSuite("uniqWith()", () => {
Expand All @@ -459,14 +459,14 @@ Rhum.testSuite("uniqWith()", () => {
{ x: 1, y: 2 },
{ x: 2, y: 1 },
{ x: 1, y: 2 },
]
],
),
[
{ x: 1, y: 2 },
{ x: 2, y: 1 },
]
],
);
}
},
);
});
Rhum.testSuite("unzip()", () => {
Expand All @@ -480,7 +480,7 @@ Rhum.testSuite("unzip()", () => {
["a", "b"],
[1, 2],
[true, false],
]
],
);
});
});
Expand Down
10 changes: 5 additions & 5 deletions src/array/cartesianProduct.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export const cartesianProduct = <T, U>(a: T[], b: U[]): [T, U][] => {
const output: [T, U][] = [];
for(const aElem of a){
for(const bElem of b){
const output: [T, U][] = [];
for (const aElem of a) {
for (const bElem of b) {
output.push([aElem, bElem]);
}
}
return output;
}
};

export default cartesianProduct;

/*
cartesianProduct(['x', 'y'], [1, 2]);
// [['x', 1], ['x', 2], ['y', 1], ['y', 2]]
*/
*/
2 changes: 1 addition & 1 deletion src/array/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export const chunk = <T>(arr: T[], size = 1): T[][] => {
return output;
};

export default chunk;
export default chunk;
10 changes: 5 additions & 5 deletions src/array/chunkIntoParts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import chunk from './chunk.ts';
import chunk from "./chunk.ts";

export const chunkIntoParts = <T>(arr: T[], parts = 1): T[][] => {
const size = Math.ceil(arr.length / parts);
return chunk(arr, size);
}
const size = Math.ceil(arr.length / parts);
return chunk(arr, size);
};

export default chunkIntoParts;
export default chunkIntoParts;
5 changes: 4 additions & 1 deletion src/array/differenceWith.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { Comparator } from "../types/Comparator.d.ts";

export const differenceWith = <T>(
comparator: Comparator<T>, a: T[], b: T[]) => {
comparator: Comparator<T>,
a: T[],
b: T[],
) => {
const diffs: T[] = [];
for (const val of a) {
if (!b.some((bVal) => comparator(val, bVal))) {
Expand Down
6 changes: 3 additions & 3 deletions src/array/dropWhile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Predicate } from "../types/Predicate.d.ts";

export const dropWhile = <T>(
arr: T[],
predicate: Predicate<T>
predicate: Predicate<T>,
): T[] => {
const l = arr.length;
let cursor = 0;
while (cursor < l && predicate(arr[cursor])) {
cursor += 1
cursor += 1;
}
return arr.slice(cursor);
};

export default dropWhile;
export default dropWhile;
4 changes: 2 additions & 2 deletions src/array/dropWhileRight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Predicate } from "../types/Predicate.d.ts";

export const dropWhileRight = <T>(
arr: T[],
predicate: Predicate<T>
predicate: Predicate<T>,
): T[] => {
const l = arr.length;
let i = l - 1;
Expand All @@ -12,4 +12,4 @@ export const dropWhileRight = <T>(
return arr.slice(0, i + 1);
};

export default dropWhileRight;
export default dropWhileRight;
4 changes: 2 additions & 2 deletions src/array/findLastIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Predicate } from "../types/Predicate.d.ts";

export const findLastIndex = <T>(
arr: T[],
predicate: Predicate<T>
predicate: Predicate<T>,
): number => {
const l = arr.length;
let i = l - 1;
Expand All @@ -12,4 +12,4 @@ export const findLastIndex = <T>(
return i;
};

export default findLastIndex;
export default findLastIndex;
4 changes: 2 additions & 2 deletions src/array/flatten.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import flattenDepth from './flattenDepth.ts';
import flattenDepth from "./flattenDepth.ts";

export const flatten = (arr: any[]) => flattenDepth(arr, 1);

export default flatten;
export default flatten;
4 changes: 2 additions & 2 deletions src/array/flattenDeep.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import flattenDepth from './flattenDepth.ts';
import flattenDepth from "./flattenDepth.ts";

export const flattenDeep = (arr: any[]) =>
flattenDepth(arr, Number.MAX_SAFE_INTEGER);

export default flattenDeep;
export default flattenDeep;
5 changes: 2 additions & 3 deletions src/array/flattenDepth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export const flattenDepth = (arr: any[], level = 1, currLevel = 1) => {
const clone = arr.slice();
if (level === 0) {
Expand All @@ -10,10 +9,10 @@ export const flattenDepth = (arr: any[], level = 1, currLevel = 1) => {
output = output.concat(
Array.isArray(elem) && currLevel < level
? flattenDepth(elem, level, currLevel + 1)
: elem
: elem,
);
}
return output;
};

export default flattenDepth;
export default flattenDepth;
4 changes: 2 additions & 2 deletions src/array/fromPairs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const fromPairs = <K extends string | number | symbol, T>(
arr: Array<any[]>
arr: Array<any[]>,
): Record<K, T> => {
const record: Record<K, T> = {} as Record<K, T>;
for (const tuple of arr) {
Expand All @@ -12,4 +12,4 @@ export const fromPairs = <K extends string | number | symbol, T>(
return record;
};

export default fromPairs;
export default fromPairs;
Loading

0 comments on commit f018845

Please sign in to comment.