I wrote out this basic functionality in ES5 that works for browsers. What it's supposed to do is iterate over a list of character/ encoding pairings and convert them through a passed string/ query. I know there is probably a sleeker way of writing this archaic code style. Would you guys mind taking a minute to share your implementation?
I have been writing Python for a year now and am rusty in ES7.
function encodeURLBreakers(query) {
var URLBreakers = {
'/': '%2F',
'?': '%3F',
'#': '%23'
};
for (var key in URLBreakers) {
var reg = '/' + URLBreakers[key] + '/g';
query.replace(key, reg);
}
return query;
}
What would be a good way to refactor this into a reusable function using a map type loop over the Javascript Object.
This is all I've tried and it works, but it uses old syntax. I am very interested in learning and using modern JS (ES7) paradigms to improve my code.