Strike Through

Benchmark publishedon

Test Runner

Initializing...

Testing in
Test CaseOps/sec
while
function strikeThrough(value: string) {
  let i = 0;     
  while (i < value.length && (value[i] === ' ' || value[i] === '\t')) {       
    i++;     
  }      
  const indent = value.slice(0, i);     
  const text = value.slice(i);      
  if (!text) return indent;     
  return `${indent}<s>${text}</s>`;   
}
strikeThrough("   <b>aaa</b>");
ready
trim
function strikeThrough(value: string) {
  const text = value.trimLeft();
 if (!text) return value;
  const indent = value.slice(0,value.length-text.length);
  return `${indent}<s>${text}</s>`;  
}
strikeThrough("   <b>aaa</b>");
ready
regex
function strikeThrough(value: string) {
  const m=/^(\s*)(.*)$/s.exec(value);
  if (!m[2]) return m[1];
  return `${m[1]}<s>${m[2]}</s>`;
}
strikeThrough("   <b>aaa</b>");
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

Revision 1
publishedon