function removeLastWord(s: string) {
const indexOfLastSpace = s.lastIndexOf(' ');
if (indexOfLastSpace === -1) {
return s;
}
return s.substring(0, indexOfLastSpace);
}
let str: string = "javascript php c++ typescript node.js";
str = removeLastWord(str);
console.log(str);
/*
run:
javascript php c++ typescript
*/