There is a 4x4 board with a total of 16 letters. In this array [2,1] represents the letter in the third row, second column.
const coordPairs = [
[ [2, 1], [4, 1] ]
[ [4, 0], [4, 1], [4, 2], [4, 3] ]
[ [0, 0], [0, 1], [0, 2] ],
[ [1, 0], [3, 0], [4, 0] ]
]
Trying to figure out how I can link a pair like [2,1] to a single letter on the game board, which is represented by an array of 16 strings (letters).
End goal is for the function to produce strings for the words based on the game board and coordinates you provide.
JSFiddle with comments: https://jsfiddle.net/8euxzgy2/4/
Assuming this is zero indexed square matrix. You can take the number of rows * coord[0] + coord[1]
:
let str = "abcdefghijklonop"
let rows = 4
const coordPairs = [[0, 0], [2, 1], [3, 1] ];
/* a b c d
* e f g h
* i j k l
* m n o p */
letters = coordPairs.map(coord => str[coord[0]* rows + coord[1]])
console.log(letters)