The goal of the swap function is to replace the strings enclosed by {{}} in the class's this.string with the corresponding items in the map that is passed into the swap method.
class Swapper
{
constructor(arg)
{
this.string = arg;
}
/*I pass in a map that dictates what to swap*/
swap(map)
{
this.string.replace(/\{\{([^}]+)\}\}/g, (_, i) => map[i]);
}
}
When I test the class method with:
const item = new Swapper('Hello {{replace1}}! {{replace2}}.');
/*tests*/
console.log(item.string);
console.log(item.swap({replace1: "World", replace2: "bye"}));
item.swap({replace1: "World", replace2: "bye"});
console.log(item.string);
none of the trys are succesful. Output says:
Hello {{replace1}}! {{replace2}}.
undefined
Hello {{replace1}}! {{replace2}}.
but I want the string to be changed to "Hello World! bye."