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 = choices => minimumBy(
comparing(compose(length, findMoves)),
choices
),
options = findMoves(path[0]);
Line 4,041 ⟶ 4,040:
 
// minimumBy :: (a -> a -> Ordering) -> [a] -> a
const minimumBy = (f, => xs) =>
xs.reduce((a, x) => undefined === a ? x : (
0 > f(x, a) ? x : a
9,655

edits