Javascript String replaceAll(toReplace, replacee)
// Problem 5. nbsp // Write a function that replaces non breaking white-spaces in a text with var testString = ' This string is made with the purpose of having white spaces which can then be replaced with " ".'; String.prototype.replaceAll = function(toReplace, replacee) { var workString = this; while (workString.indexOf(toReplace) > -1) { workString = workString.replace(toReplace, replacee); }// w w w . j a va 2s .c o m return workString; } var workedOn = testString.toUpperCase().replaceAll(' ', '&nbps'); console.log(workedOn);