v1
3/9/2021 by cmdcolin -00
Setup HTML - click to add setup HTML
Setup JS - click to add setup JavaScript
delete caserun single casemove downdrag and drop case


ready



function countCharacter_reduce(str, ch) {
  return Array.prototype.reduce.call(str, (prev, cur) => cur === ch && ++prev && prev, 0);
}

for(let i = 0; i < 10000; i++) {
	countCharacter_reduce('this/is/a/path/with/extension', '/' )
}
delete caserun single casemove upmove downdrag and drop case


ready




function countCharacter_split(str, ch) {
  return str.split(ch).length - 1;
}

for(let i = 0; i < 10000; i++) {
	countCharacter_split('this/is/a/path/with/extension', '/' )
}
delete caserun single casemove upmove downdrag and drop case


ready




function countCharacter_for(str, ch) {
  for (var count = 0, ii = 0; ii < str.length; ii++) {
    if (str[ii] === ch)
      count++;
  }
  return count;
}

for(let i = 0; i < 10000; i++) {
	countCharacter_for('this/is/a/path/with/extension', '/' )
}
delete caserun single casemove upmove downdrag and drop case


ready




function countCharacter_regex(str, ch) {
  return str.length - str.replace(new RegExp(ch, 'g'), '').length;
}

for(let i = 0; i < 10000; i++) {
	countCharacter_regex('this/is/a/path/with/extension', '/' )
}
delete caserun single casemove updrag and drop case


ready




function countCharacter_indexOf(str, char) {
  var start = 0;
  var count = 0;
  while ((start = str.indexOf(char, start) + 1) !== 0) {
    count++;
  }
  return count;
}

for(let i = 0; i < 10000; i++) {
	countCharacter_indexOf('this/is/a/path/with/extension', '/' )
}
Test Case - click to add another test case
Teardown JS - click to add teardown JavaScript
Output (DOM) - click to monitor output (DOM) while test is running
RUN