RegExp only returns boolean, there is NO reason to be screwing around with === true

It's a function, say function instead of dicking around with const and the painfully and needlessly cryptic arrow function. (More true if working client-side than server-side)

Why are you wasting time splitting the string? You can array-like iterate strings, and I'd suggest a

while ('' !== (char = String.charAt(i++))) {

For that loop avoiding the pointless string split. Likewise since you're pushing what will be converted to string, don't screw around with building an array you're just going to join. A few well placed quotes and you're good to go.

Though honestly, I can't figure out what this is even supposed to do or why. Looks like the type of typical career educator "never had to write real code in their life" pedanticry.

Although I suspect moving the break / match logic into the first loop and ditching the second loop entirely would simplify matters.

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store