Late, but very happy with this one and had a lot of fun
Node.js
constisUpperCase=letter=>letter===letter.toUpperCase();constisLowerCase=letter=>letter===letter.toLowerCase();constlettersAreEqual=(a,b)=>a.toUpperCase()===b.toUpperCase();constlast=array=>array[array.length-1];constunique=array=>[...newMap(array.map(s=>[s.toLowerCase(),s])).values()];constdoesReact=(a,b)=>{letreacts=false;if((isLowerCase(a)&&isUpperCase(b))||(isUpperCase(a)&&isLowerCase(b))){if(lettersAreEqual(a,b)){reacts=true;}}returnreacts;};constremovePolarity=polymer=>{polymer=[...polymer];constoutput=[""];for(constcharofpolymer){if(doesReact(char,last(output))){output.pop();}else{output.push(char);}}// minus one for the emptry string at the startreturnoutput.length-1;};constbestPolarity=polymer=>{polymer=[...polymer];constuniqueLetters=unique(polymer);constresults=uniqueLetters.map(letter=>{conststrippedPolymer=polymer.filter(c=>!lettersAreEqual(c,letter));returnremovePolarity(strippedPolymer);});returnMath.min.apply(null,results);};
Late, but very happy with this one and had a lot of fun
Node.js
Full code: github.com/MattMorgis/Advent-Of-Co...