Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

matrix calculator in js

let a = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
];
let b = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
];

let result = 0;

if (a.length === 3 && b.length === 3) {
  console.log(a[0][0] + b[0][0], a[0][1] + b[0][1], a[0][2] + b[0][2]);
  console.log(a[1][0] + b[1][0], a[1][1] + b[1][1], a[1][2] + b[1][2]);
  console.log(a[2][0] + b[2][0], a[2][1] + b[2][1], a[2][2] + b[2][2]);
  
  // this nested for loop shows the output in one line rather than in matrix form
  /*
  for (let row = 0; row <= 2; row++) {
    for (let col = 0; col <= 2; col++) {
      result = a[row][col] + b[row][col];
      console.log(result);
     }
  }
  */
} else {
  console.log("It works only for 3x3 matrix");
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript WeakMaps Are Not iterable 
Javascript :: JavaScript Destructuring - Before ES6 
Javascript :: javascript typeof operator returns function 
Javascript :: fetch second parameters 
Javascript :: javascript "use strict" 
Javascript :: JavaScript Generator Throw Method 
Javascript :: javaScript values() Method 
Javascript :: Save multiple Child 
Javascript :: alphanumeric without space regex 
Javascript :: json syntax 
Javascript :: chart js svg word map 
Javascript :: How to export functions and import them in js 
Javascript :: javascript template string condtioning 
Javascript :: change x scale phaser 
Javascript :: phaser place on rectangle shift 
Javascript :: phaser animation from json 
Javascript :: add multiple phone using js 
Javascript :: remove text and keep div inside a div jquery 
Javascript :: hook use effect with class 
Javascript :: TypeError: (0 , import_dev.useParams) is not a function remix 
Javascript :: Set A Function For An Element 
Javascript :: .pop javascript 
Javascript :: event listeners 
Javascript :: array sort 
Javascript :: javascript array map 
Javascript :: stringbuffer javascript 
Javascript :: is multiple select javascript 
Javascript :: javascript autocomplete 
Javascript :: jsoup 
Javascript :: useStyles 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =