Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 countInArray = (array, value) => {
- let count = 0;
- for (let i = 0; i < array.length; i++) {
- if (array[i] === value) {
- count++;
- }
- }
- return count;
- }
- const isPrime = value => {
- for (let i = 2; i < value; i++)
- if (value % i === 0) return false;
- return value > 1;
- }
- const filterArray = (arrayA, arrayB) => {
- let i = 0
- const matchingValues = []
- do {
- if (!isPrime(countInArray(arrayB, arrayA[i]))) {
- matchingValues.push(arrayA[i])
- }
- i++
- } while (i < arrayA.length)
- return matchingValues
- }
- const result = filterArray(A, B)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement