JSFiddle - React, Tailwind, and code Playground

by hescano

JavaScript

function solution(str) {
   var result = [];
   var arr = str.split('');
   while (arr.length > 1) {
   	result.push(arr.splice(0, 2).join(''));
   }
   if (arr.length > 0) {
   	result.push(arr[0] + "_")
   }
   return result;
}

console.log(solution("abc"));