Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // example:
- //[ [ 16, 32, 64, 128, 256, 512 ],
- // [ 8, 16, 32, 64, 128, 256 ],
- // [ 4, 8, 16, 32, 64, 128 ],
- // [ 2, 4, 8, 16, 32, 64 ],
- // [ 1, 2, 4, 8, 16, 32 ] ]
- function fillMatrix(rows, cols){
- var matrix = [];
- for (var row = rows - 1; row >= 0; row -= 1) {
- matrix[row] = [];
- for (var col = 0; col < cols; col += 1) {
- matrix[row][col] = Math.pow(2, col + (rows - row) - 1);
- }
- }
- return matrix;
- }
- // example:
- //[ [ 15, 18, 21, 24, 27, 30, 33 ],
- // [ 12, 15, 18, 21, 24, 27, 30 ],
- // [ 9, 12, 15, 18, 21, 24, 27 ],
- // [ 6, 9, 12, 15, 18, 21, 24 ],
- // [ 3, 6, 9, 12, 15, 18, 21 ],
- // [ 0, 3, 6, 9, 12, 15, 18 ] ]
- function fillMatrix(rows, cols) {
- var matrix = [];
- for (var row = rows - 1; row >= 0; row -= 1) {
- matrix[row] = [];
- for (var col = 0; col < cols; col += 1) {
- matrix[row][col] = (rows - 1 - row + col) * 3
- }
- }
- return matrix;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement