nuxy / leetcode-1071 (v3)

Revision 3 of this benchmark created on


Description

Greatest Common Divisor of Strings

Setup

const gcdOfStrings = function(str1, str2) {
  const regex = new RegExp(`${str2}(?=${str2})?`, 'g');

  return str1.match(regex) && (str1.replace(regex, '') || str2) || '';
};

Test runner

Ready to run.

Testing in
TestOps/sec
Test 1
gcdOfStrings('ABCABC', 'ABC'); // ABC
ready
Test 2
gcdOfStrings('ABABAB', 'ABAB'); // AB
ready
Test 3
gcdOfStrings('LEET', 'CODE'); //
ready

Revisions

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