← Back to challenges

Knight Move

JavaScriptHardalgebrastringsgames

Instructions

Create a function that takes a start position of the chess knight and return all possible moves.

Alternative Text Alternative Text Alternative Text Alternative Text

Formating

  • Letters (A, B, C, D, E, F, G,H) must be on Uppercase.
  • On result moves must be sorted alphabetically (numbers too).
  • Moves must be separated by space-space.

Examples

knightMove("A1") ➞ "B3 - C2"

knightMove("A2") ➞ "B4 - C1 - C3"

knightMove("E2") ➞ "C1 - C3 - D4 - F4 - G1 - G3"

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.