Skip to content

Commit

Permalink
refactor(arrays): update arg order, fix shuffle()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Feb 14, 2019
1 parent 0007152 commit b01abaa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/arrays/src/binary-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { compare } from "@thi.ng/compare";
* to identify the index of `x`. The sort order of `buf` MUST be
* compatible with that of `cmp`.
*
* @param x
* @param buf
* @param x
* @param key
* @param cmp
*/
export const binarySearch = <A, B>(
x: A,
buf: ArrayLike<A>,
x: A,
key: Fn<A, B> = (x) => <any>x,
cmp: Comparator<B> = compare,
) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/arrays/src/fuzzy-match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import { equiv as _eq } from "@thi.ng/equiv";
*
* @see thi.ng/transducers/xform/filterFuzzy
*
* @param query
* @param domain
* @param query
* @param equiv
*/
export const fuzzyMatch = <T>(
query: ArrayLike<T>,
domain: ArrayLike<T>,
query: ArrayLike<T>,
equiv: Predicate2<any> = _eq
) => {
const nd = domain.length;
Expand Down
13 changes: 12 additions & 1 deletion packages/arrays/src/shuffle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { IRandom, SYSTEM } from "@thi.ng/random";

/**
* Shuffles the first `n` items of given array, using Fisher-yates and
* optional `rnd` PRNG. If `n` is `undefined`, the entire array will be
* shuffled.
*
*
* @param buf
* @param n
* @param rnd
*/
export const shuffle =
(buf: any[], n = buf.length, rnd: IRandom = SYSTEM) => {
const l = buf.length;
n = Math.min(n, buf.length);
const l = n;
if (l > 1) {
n = Math.min(n, l);
while (--n >= 0) {
Expand Down

0 comments on commit b01abaa

Please sign in to comment.