Javascript Palindromes (v3)

Revision 3 of this benchmark created by Justine Philip on


Setup

var sampleText = "tattarrattat"
  
  function palindromeIntuitive(text) {
  var reversedText  = text.toLowerCase()
                      .split('').reverse().join('');
  
  
  return text === reversedText;
  }
  
  
  function palindromeLoop(text) {
      let charArray = text.toLowerCase().split('')
      
      let result = charArray.every((letter, index) => {
          return letter === charArray[charArray.length - index - 1];
      })
      
      return result
  }
  
  function palindromeLoopFix(text) {
   var textLen = text.length;
   for (var i = 0; i < textLen/2; i++) {
     if (text[i] !== text[textLen - 1 - i]) {
         return false;
     }
   }
   return true;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
The Loop Method
palindromeLoop(sampleText)
ready
The Loop Method Fixed
palindromeLoopFix(sampleText)
ready
The intuitive approach
palindromeIntuitive(sampleText)
ready

Revisions

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

  • Revision 3: published by Justine Philip on