JSFiddle - React, Tailwind, and code Playground

by chovy

JavaScript

function solution(str){
  var chars = str.split('')
    , pairs = [];
  
  for ( var i = 0, l = chars.length; i < l; i = i + 2 ) {
    var a = chars[i-1]
      , b = chars[i]
      , pair = '';
      
    if ( a ) {
      pair += a;
    } 

    pair += b;
    
    pairs.push(pair);
  }

  return pairs;
}