Created
April 27, 2017 03:39
-
-
Save the-vampiire/78c585ec4871b151330cde6d947433b0 to your computer and use it in GitHub Desktop.
How in god's name does this work?
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
| // How in gods name did this work? I don't understand what I even did. It started off making sense and 25 console logs and muckeries later | |
| // it has come to this. Literally wtf. | |
| function sumPrimes(num){ | |
| var i = 2, nums = [], primes = []; | |
| while(i <= num){ | |
| nums.push(i); | |
| i++; | |
| } | |
| for(i in nums){ | |
| primes.push(i_dont_know_how_this_works(nums[i], nums)); | |
| } | |
| function flatten(a,b){ | |
| return a.concat(b); | |
| } | |
| function sum(a,b){ | |
| return a+b | |
| } | |
| function i_dont_know_how_this_works(num, arr){ | |
| var i = 0; | |
| var primes = []; | |
| for(i; i < arr.length; i++){ | |
| if(num % arr[i] === 0){ | |
| if(arr[i] !== 1 || arr[i] !== num){ | |
| primes.push(arr[i]); | |
| } | |
| } | |
| } | |
| if(primes.length === 1){ | |
| return primes; | |
| } | |
| else{ | |
| return false; | |
| } | |
| } | |
| return primes.filter(function(nums){return nums}).reduce(flatten).reduce(sum); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment