From 5794bd8c33b07bf067bdd519e4d6728b6543f188 Mon Sep 17 00:00:00 2001 From: Kaio Rosa Date: Thu, 21 Mar 2019 16:32:43 -0300 Subject: [PATCH] Add files via upload --- Intermediate Algorithm Scripting/sum-all-primes.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 Intermediate Algorithm Scripting/sum-all-primes.json diff --git a/Intermediate Algorithm Scripting/sum-all-primes.json b/Intermediate Algorithm Scripting/sum-all-primes.json new file mode 100644 index 0000000..26b4665 --- /dev/null +++ b/Intermediate Algorithm Scripting/sum-all-primes.json @@ -0,0 +1 @@ +{"index.js":"function sumPrimes(num) {\n let sum =0;\n let arr =[];\n // create an array with all the values up to num\n for(let i =2;i<=num;i++){\n let obj ={\n num: i,\n mark:0\n };\n arr.push(obj);\n }\n // implement my version Sieve of Eratosthenes\n for(let j =2;j <= num;j++){\n for(let i =0;i < arr.length; i++){\n if(arr[i].num %j === 0 && arr[i].num !== j){\n arr[i].mark = 1;\n }\n }\n }\n // sum the array of prime numbers\n for(let k =0;k < arr.length;k++){\n if(arr[k].mark === 0){\n sum += arr[k].num;\n console.log(arr[k].num);\n }\n }\n\n return sum;\n}\n\nconst sum = sumPrimes(10);\nconsole.log(sum);"} \ No newline at end of file