Workshop › 15 Puzzle › Step 5 of 27
To draw position i we need its row and column. With N = 4 squares per row, the row is i / N rounded down, and the
column is the remainder of that division.
```js
const N = 4 // 4 by 4: tiles 1 to 15 and one gap
const rowOf = (i) => Math.floor(i / N)
const colOf = (i) => i % N
```N is the board size, named once.(i) => ... is a short function (an arrow function): given i, it gives back what is after the arrow.Math.floor rounds down: 6 / 4 is 1.5, so position 6 is in row 1.% is the remainder: 6 % 4 is 2, so position 6 is in column 2.let tiles, write the N line and leave an empty line.let tiles, leave an empty line and write rowOf and colOf. Press Run.Skills: Arrays and objects, Functions
← A function that draws Where each square is →