JSFiddle - React, Tailwind, and code Playground
by danbeam
JavaScript
function escapeSpaces(str) {
return str.split(/ /g).join('%20');
}
function assertEquals(str1, str2) {
console.log(str1, str2);
if (str1 != str2)
throw 'fail';
}
assertEquals(escapeSpaces(' '), '%20');
assertEquals(escapeSpaces(' a '), '%20a%20');
assertEquals(escapeSpaces(' b %20 c '), '%20b%20%20%20c%20');