Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const assert = require('assert');
- const isPrime = (n) => {
- if (n <= 1) return false
- else if (n <= 3) return true
- else if (n % 2 === 0 || n % 3 === 0) return false
- let i = 5;
- while (i * i <= n) {
- if(n % i === 0 || n % (i + 2) === 0) return false
- i += 6
- }
- return true;
- }
- const count = (array, n) => {
- const filtered = array.filter(a => a === n);
- console.log(n, filtered, filtered.length);
- return filtered.length;
- }
- const filter = (fst, snd) => {
- return fst.reduce((acc, a) => {
- if(isPrime(count(snd, a)))
- return acc
- return acc.concat(a);
- }, [])
- }
- const a = [2,3,9,2,5,1,3,7,10]
- const b = [2,1,3,4,3,10,6,6,1,7,10,10,10]
- const c = [2,9,2,5,7,10]
- assert.deepEqual(filter(a, b), c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement