Advertisement
simonradev

tes

Feb 26th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. (function result() {
  2.     function binary(a, b, operation) {
  3.         const array = [];
  4.         for (let index = 0; index <= 1; index++) {
  5.             const result = operation(a[index], b[index]);
  6.             array.push(result);
  7.         }
  8.  
  9.         return array;
  10.     }
  11.  
  12.     function product(a, b) {
  13.         return a * b;
  14.     }
  15.  
  16.     function add(a, b) {
  17.         return binary(a, b, (a, b) => a + b);
  18.     }
  19.  
  20.     function multiply(a, b) {
  21.         return binary(a, b, product);
  22.     }
  23.  
  24.     function length(a) {
  25.         return Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2));
  26.     }
  27.  
  28.     function dot(a, b) {
  29.         return binary(a, b, product).reduce((prev, curr) => prev + curr, 0);
  30.     }
  31.  
  32.     function cross(a, b) {
  33.         return a[0] * b[1] - a[1] * b[0];
  34.     }
  35.    
  36.     return {
  37.         'add': add,
  38.         'multiply': multiply,
  39.         'length': length,
  40.         'dot': dot,
  41.         'cross': cross,
  42.     };
  43. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement