Knight's tour: Difference between revisions
m
→Functional JavaScript: (simplified the warnsdorff function definition slightly with a curried minimumBy)
m (→Functional JavaScript: (simplified the warnsdorff function definition slightly with a curried minimumBy)) |
|||
Line 3,800:
const
findMoves = xy => difference(knightMoves(xy), path),
warnsdorff =
comparing(compose(length, findMoves))
),
options = findMoves(path[0]);
Line 4,041 ⟶ 4,040:
// minimumBy :: (a -> a -> Ordering) -> [a] -> a
const minimumBy =
xs.reduce((a, x) => undefined === a ? x : (
0 > f(x, a) ? x : a
|