Is there an algorithm to create a matrix with the following output format?
1, 3, 5, 7, 9
2, 4, 6, 8, 10
11, 13, 15, 17, 19
20, 22, 24, 26, 28
I'm particularly interested in a JavaScript solution, but what I need most is the algorithm itself.
Thank you.
I attempted this approach:
let arr = [];
for(let i = 0; i < 2; i++){
arr[i] = []
for(let j = 0; j < 5; j++){
if(j % 2 ==0){
arr[j] = i
}
}
}
console.log(arr)