nuxy / leetcode-1768

Benchmark created on


Description

Merge Strings Alternatively

Setup

const mergeAlternately = function(word1, word2) {
  word1 = word1.split('');
  word2 = word2.split('');

  const len = [...word1, ...word2].length;

  let str = '';

  for (let i = 0; i < len; i++) {
    str += (i % 2)
      ? word2.shift() || word1.shift()
      : word1.shift() || word2.shift();
  }

  return str;
};

Test runner

Ready to run.

Testing in
TestOps/sec
Test 1
mergeAlternately('abc', 'pqr'); // apbqcr
ready
Test 2
mergeAlternately('ab', 'pqrs'); // apbqrs
ready
Test 3
mergeAlternately('abcd', 'pq'); // apbqcd
ready

Revisions

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