John_IV

vectors

Jun 13th, 2020
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (() => {
  2.     let add = (v1, v2) => [v1[0] + v2[0], v1[1] + v2[1]];
  3.     let multiply = (v1, sc) => [v1[0] * sc, v1[1] * sc];
  4.     let length = (v1) => Math.sqrt(Math.pow(v1[0], 2) + Math.pow(v1[1], 2));
  5.     let dot = (v1, v2) => v1[0] * v2[0] + v1[1] * v2[1];
  6.     let cross = (v1, v2) => v1[0] * v2[1] - v1[1] * v2[0];
  7.  
  8.     return {add, multiply, length, dot, cross};
  9. })();
Advertisement
Add Comment
Please, Sign In to add comment