Feedback on: irt.org FAQ Knowledge Base Q1658
Worth:
Very worth reading
Length:
Just right
Technical:
Just right
Comments:
i think "if (i>0 && i%4 == 0)" should be "if (i>0 && i%nth == 0)"
Worth:
Worth reading
Length:
Just right
Technical:
Just right
Comments:
Would this work better?
<script language="JavaScript"><!--
function insertNthChar(string,chr,nth) {
var output = '';
for (var i=0; i<string.length; i++) {
if (i>0 && i%nth == 0)
{
output += chr;
}
else
{
output += string.charAt(i);
}
}
return output;
}
alert(insertNthChar('erty1f213dfs1111', '-', 4));
//--></script>
Worth:
Very worth reading
Length:
Just right
Technical:
Just right
Comments:
I have been attempting to write a similar function for the last hour; I was ready to mash my scrotum into a paste with a brick out of anger until I came across this great solution! Thanks!