I am trying to make a function that adds a space between "flight" and "###" but would like to make it work if the flight number is greater than 3 digits. I know I could make the second part of the slice method a huge number and it would technically work but I figure there should be a more elegant way. Any help would be appreciated, thanks!
const addSpace = function (str) {
const flightNumber = str.slice(6, 9);
return [str.slice(0, 6) + ' ' + flightNumber]
}
console.log(...addSpace('flight843'));