product of two vector

Solutions on MaxInterview for product of two vector by the best coders in the world

showing results for - "product of two vector"
Dario
05 Nov 2017
1
2let vectors = [[7, 1, 1],[6, 0, 2], [5, 7, 0], [3, 1, 2], [2, 3 ,8], [0, 0, 0]]
3
4function dotProduct(vector1, vector2){
5    let result = 0;
6    for(let i = 0; i < vector1.length; i++){
7        result += vector1[i] * vector2[i]
8      }
9    return result
10  }
11  
12  for(let i = 0; i < vectors.length; i++){
13    for(let j = i + 1; j < vectors.length; j++){
14      if(dotProduct(vectors[i], vectors[j]) === 0){
15          console.log(`${vectors[i]} and ${vectors[j]} are orthogonal `)
16      }
17    }
18  }
19