bartekkozak

Untitled

Nov 19th, 2019
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const A = [2, 3, 9, 2, 5, 1, 3, 7, 10]
  2. const B = [2, 1, 3, 4, 3, 10, 6, 6, 1, 7, 10, 10, 10]
  3.  
  4. const countInArray = (array, value) => {
  5. let count = 0;
  6. for (let i = 0; i < array.length; i++) {
  7. if (array[i] === value) {
  8. count++;
  9. }
  10. }
  11. return count;
  12. }
  13.  
  14. const isPrime = value => {
  15. for (let i = 2; i < value; i++)
  16. if (value % i === 0) return false;
  17. return value > 1;
  18. }
  19.  
  20. const filterArray = (arrayA, arrayB) => {
  21. let i = 0
  22. const matchingValues = []
  23.  
  24. do {
  25. if (!isPrime(countInArray(arrayB, arrayA[i]))) {
  26. matchingValues.push(arrayA[i])
  27. }
  28. i++
  29. } while (i < arrayA.length)
  30.  
  31. return matchingValues
  32. }
  33.  
  34. const result = filterArray(A, B)
RAW Paste Data