function moveWordToEnd(s: string, word: string): string {
// Split on whitespace
const parts: string[] = s.trim().split(/\s+/);
// Find and remove the first occurrence
const index = parts.indexOf(word);
if (index !== -1) {
parts.splice(index, 1); // remove it
parts.push(word); // append at end
}
// Rebuild the string
return parts.join(" ");
}
const s = "Would you like to know more? (Explore and learn)";
const word = "like";
const result = moveWordToEnd(s, word);
console.log(result);
/*
run:
"Would you to know more? (Explore and learn) like"
*/