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