SHARE
TWEET

Untitled

a guest Mar 26th, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var assert = require('assert');
  2.  
  3. const A = [2,3,9,2,5,1,3,7,10]
  4. const B = [2,1,3,4,3,10,6,6,1,7,10,10,10]
  5. const C = [2,9,2,5,7,10]
  6.  
  7. const isPrime = n => ![...Array(n).keys()].slice(2).map(i => !(n%i)).includes(true) && ![0,1].includes(n)
  8.  
  9. const excludedValues = B.filter((x, i, array) => {
  10.     const isUnique = array.indexOf(x) === i
  11.     if (!isUnique) return false
  12.  
  13.     const count = array.filter(y => y === x).length
  14.     return isPrime(count)
  15. });
  16.  
  17. const result = A.filter(x => !excludedValues.includes(x))
  18.  
  19. //OK
  20. assert.deepEqual(C, result)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top