Untitled

Run Settings
LanguageJavaScript
Language Version
Run Command
function maxProd(solarPanel){ solarPanel.sort(function(a, b){return a - b}); //count negative numbers let negUse=0, negProduct=solarPanel[0], posProduct=solarPanel[0]; for(let x of solarPanel){ if(x<0){ negUse++; } else{ break; } } console.log("negUse= ", negUse); if(negUse===0){ negProduct=1; } for(let i=0; i<negUse; i++){ if(i===0){ negProduct=solarPanel[i]; continue; } console.log("neg= ",solarPanel[i]) negProduct*=solarPanel[i]; } for(let i=solarPanel.length-1; i>-1; i--){ if(solarPanel[i]<1){ break; } else{ if(i===solarPanel.length-1){ posProduct=solarPanel[i]; continue; } console.log("pos= ",solarPanel[i]) posProduct*=solarPanel[i]; } } console.log(posProduct," ",negProduct); if(posProduct>0) return (posProduct*negProduct); } console.log(maxProd([-2, 0, -2, -2, 0]));
Editor Settings
Theme
Key bindings
Full width
Lines