Last active
March 25, 2021 06:27
-
-
Save balazsnemeth/352e3230a0868ea811817e919a044f07 to your computer and use it in GitHub Desktop.
Solution for Count Non Divisible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Solution for CountNonDivisible (Codility) | |
// Not the best, just O(N^2)... | |
// https://codility.com/programmers/lessons/11-sieve_of_eratosthenes/count_non_divisible/ | |
function solution(A) { | |
// write your code in JavaScript (Node.js 6.4.0) | |
const divisors = A.map(e => 0); | |
for (let i = 0; i<A.length; i++) { | |
let e = A[i]; | |
for (let j = i+1; j<A.length; j++) { | |
let f = A[j]; | |
if (f % e === 0) { | |
divisors[j]++; | |
} | |
if (e % f === 0) { | |
divisors[i]++; | |
} | |
} | |
} | |
const res = divisors.map(e => A.length - e - 1); | |
// console.log("res: ", res); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's my solution, you can check: https://app.codility.com/demo/results/trainingDWZVT3-E7U/