I am trying to solve a problem in JavaScript. I have a string text consisting of English word. I need to find all the capital and lowercase F's in a word and need to insert T in front of that word. Please help me! Thank you.
function addTbeforeFs(text, chr) { var output = ''; for (var i = 0; i < text.length; i++) { if (i % 3 === 0) output += chr; output += text.charAt(i); } return output; } alert(addTbeforeFs('Fluffy', 'T')); //My Output is : TFluTffy // Expected Output should be: TFluTfTfy
chr
i % 3 === 0
function addLetterBeforeFs(text, letterToAdd) { return text.replace(/f/gi, letterToAdd + "$&"); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)