Tell us what’s happening:
So my code for this problem is inefficient and I can’t get it to execute without crashing. This is as far as I’ve come and I commented out the next logical steps in my mind once I can get what I have so far to work.
What is causing my code to crash and am I on the right path logically?
Your code so far
function euler95() {
function propSums(n){
let output = []
for (let i = 1; i < n; i++){
if (n%i===0){
output.push(i)
}
}
if (output.length === 0){
return 0
}else {
return output.reduce((a,b)=> a+=b)
}
}
let j;
let chain = []
let amicChain = []
for (let i = 1; propSums(i) <= 1000000; i++){
chain = []
j = i
while (j !== propSums(i)){
i = propSums(i)
chain.push(i)
if (propSums(i) === 0){
break
}
}
amicChain.push(chain)
}
// sort amicChain by length of sub-arrays from biggest -> smallest
// return amicChain[0][0]
}
euler95();
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.
Link to the challenge: