creating a nested loop of a chessboard in javascript

Solutions on MaxInterview for creating a nested loop of a chessboard in javascript by the best coders in the world

showing results for - "creating a nested loop of a chessboard in javascript"
Matthieu
13 Aug 2017
1function chessboard() {
2
3    let columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
4    let rows = [1, 2, 3, 4, 5, 6, 7, 8];
5
6    const chessboard = [];
7    
8    for(let i = 0; i<columns.length; i++){
9        let currentRow = [];
10        // console.log (columns[i])
11            for (let j = 0; j < rows.length; j++){
12            // console.log(rows[j]);
13            currentRow.push(`${columns[i]} - ${rows[j]}`)
14        } 
15    
16        // console.log(currentRow) 
17        // return position
18        chessboard.push(currentRow)
19    } 
20    console.log(chessboard)
21
22    return chessboard;
23}
24module.exports = chessboard;