"I? love ?? the ?great ? ?wall in ?beijing" .split("") .reduce((acc, cur, index) => { return cur == "?" || (cur == " " && acc[acc.length - 1] == " ") ? acc : [...acc, cur]; }, []) .join("") .replace("g", "G") .replace("w", "W") .replace("b", "B");