Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let counter = 0;
  2. let output = "";
  3. const print = (txt) => output += txt;
  4. const printPreceded  = (precede, txt) => output += (precede ? ", " : "") + txt;
  5. const are_pair = (a, b) => a %2 === 0 && b%2 ===0;
  6. const process = (precede, a,b) =>  are_pair(a,b) ? printPreceded(precede, a+b)
  7.                                  : a === b ? printPreceded(precede, a)  
  8.                                  : printPreceded(precede, counter);
  9. const run= (name1, arr1, name2, arr2) => {
  10.     print(`\ncomparing ${name1} and ${name2}\n`);
  11.     let flag = 0;
  12.     for(i of arr1)
  13.     for(j of arr2){ ++counter; process(flag++, i, j); }
  14. }
  15. const a = [7,6,5,4]; const b = [9, 7, 5 , 3 ] ; const c = [4,6,8,2];
  16. counter = 0; run("apple", a, "samsung", b); run("apple", a, "huawei", c); run("huawei", c, "samsung", b);
  17. console.log(output);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement