I'm trying to make a SMS Shortner for a kata at [codewars](http://codewars.com). >Your task is to shorten the message to 160 characters, starting from end, by replacing spaces with camelCase, as much as necessary. I've tried with a while loop and although the logic is correct, it's taking too long to process my tests. const shortener = (message) => { let r = message.split('').reverse().join(''); while (r.length > 160) { r = r.replace(/([^\s]\s)/, (m,s) => s.trim().toUpperCase()); } return r.split('').reverse().join(''); } My question is how can I optmize this and what parts are taking longer than it could?