function splitStringInto3WordLines(str) {
const words = str.split(" ");
const threeWordLines = [];
for (let i = 0; i < words.length; i += 3) {
const oneLine = words.slice(i, i + 3).join(" ");
threeWordLines.push(oneLine.trim());
}
return threeWordLines;
}
const str = "node.js c c++ python rust go php typescript";
const threeWordLines = splitStringInto3WordLines(str);
threeWordLines.forEach(line => {
console.log(line);
});
/*
run:
node.js c c++
python rust go
php typescript
*/