CLooker

solution to hackerRank problem

Jan 24th, 2018
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // https://www.hackerrank.com/challenges/between-two-sets/problem
  2.  
  3. function getTotalX(a, b) {
  4.   return Array.from(Array(b[0])).reduce((aFactors, _, index) => {
  5.     const i = (index + 1);
  6.     let flag = true;
  7.     a.forEach(num => (i % num !== 0) && (flag = false))
  8.     return flag === true ? aFactors.push(i) && aFactors : aFactors
  9.   }, []).reduce((answer, aNum) => {
  10.     let flag = true;
  11.     b.forEach(bNum => (bNum % aNum !== 0) && (flag = false))
  12.     return flag === true ? answer.push(aNum) && answer : answer;
  13.   }, []).length
  14. }
Add Comment
Please, Sign In to add comment