function removeLastOccurrenceOfAWordFromAString(str, word) {
// Find the position of the last occurrence of word in str
const pos = str.lastIndexOf(word);
if (pos !== -1) {
str = str.substring(0, pos) + str.substring(pos + word.length);
}
return str;
}
const str = "javascript c python javascript c++ javascript php rust";
const word = "javascript";
const result = removeLastOccurrenceOfAWordFromAString(str, word);
console.log(result);
/*
run:
javascript c python javascript c++ php rust
*/