From 8ca6f5e3db4440b8a6edc25b574ae613f394bc32 Mon Sep 17 00:00:00 2001 From: Dennis Bauer Date: Sun, 8 Mar 2026 10:55:56 +0100 Subject: [PATCH 1/3] Setup problem --- Problems/Remove-The-Last-Vowel/README.md | 22 +++++++++++++++++++ .../remove-the-last-vowel.test.ts | 7 ++++++ Problems/Remove-The-Last-Vowel/solver.ts | 1 + 3 files changed, 30 insertions(+) create mode 100644 Problems/Remove-The-Last-Vowel/README.md create mode 100644 Problems/Remove-The-Last-Vowel/remove-the-last-vowel.test.ts create mode 100644 Problems/Remove-The-Last-Vowel/solver.ts diff --git a/Problems/Remove-The-Last-Vowel/README.md b/Problems/Remove-The-Last-Vowel/README.md new file mode 100644 index 0000000..39f8710 --- /dev/null +++ b/Problems/Remove-The-Last-Vowel/README.md @@ -0,0 +1,22 @@ +# Remove-The-Last-Vowel + +Write a function that removes the last vowel in each word in a sentence. + +## Documentation + +### Solution Idea + +The Idea to solve this problem + +--- + +### [Implementation](./solver.ts) + +The implementation for solving this problem + +--- + +### Information's + +This problem comes from the newsletter [Sloth Bytes](https://slothbytes.beehiiv.com). +[Post](https://slothbytes.beehiiv.com/p/5-things-tutorials-never-teach) from January 07, 2026. diff --git a/Problems/Remove-The-Last-Vowel/remove-the-last-vowel.test.ts b/Problems/Remove-The-Last-Vowel/remove-the-last-vowel.test.ts new file mode 100644 index 0000000..a6cb7d9 --- /dev/null +++ b/Problems/Remove-The-Last-Vowel/remove-the-last-vowel.test.ts @@ -0,0 +1,7 @@ +import { describe, expect, it } from "vitest"; + +describe("Removes the last vowel for each word in each sentence", () => { + it("should return something for this input", () => { + expect(true).toEqual(true); + }); +}); diff --git a/Problems/Remove-The-Last-Vowel/solver.ts b/Problems/Remove-The-Last-Vowel/solver.ts new file mode 100644 index 0000000..66f8eb6 --- /dev/null +++ b/Problems/Remove-The-Last-Vowel/solver.ts @@ -0,0 +1 @@ +export default function removeLastVowel(): void {} From b75389b3989ea54e11f518ff592824aafe93b782 Mon Sep 17 00:00:00 2001 From: Dennis Bauer Date: Sun, 8 Mar 2026 11:21:34 +0100 Subject: [PATCH 2/3] Solved the problem --- Problems/Remove-The-Last-Vowel/README.md | 9 ++++++- .../remove-the-last-vowel.test.ts | 25 +++++++++++++++++-- Problems/Remove-The-Last-Vowel/solver.ts | 17 ++++++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Problems/Remove-The-Last-Vowel/README.md b/Problems/Remove-The-Last-Vowel/README.md index 39f8710..c232dcd 100644 --- a/Problems/Remove-The-Last-Vowel/README.md +++ b/Problems/Remove-The-Last-Vowel/README.md @@ -1,6 +1,13 @@ # Remove-The-Last-Vowel -Write a function that removes the last vowel in each word in a sentence. +Write a function that removes the last vowel from each word in a sentence. + +A vowel is one of: `a, e, i, o, u` (case-insensitive). + +Each word in the sentence should be processed independently, and only the **last vowel** of each word should be removed. + +Extra challenge (TypeScript/JavaScript): +Try to implement the solution as a **one-liner**, meaning the function should contain only a `return` statement using method chaining. ## Documentation diff --git a/Problems/Remove-The-Last-Vowel/remove-the-last-vowel.test.ts b/Problems/Remove-The-Last-Vowel/remove-the-last-vowel.test.ts index a6cb7d9..548bde6 100644 --- a/Problems/Remove-The-Last-Vowel/remove-the-last-vowel.test.ts +++ b/Problems/Remove-The-Last-Vowel/remove-the-last-vowel.test.ts @@ -1,7 +1,28 @@ import { describe, expect, it } from "vitest"; +import removeLastVowel from "./solver"; describe("Removes the last vowel for each word in each sentence", () => { - it("should return something for this input", () => { - expect(true).toEqual(true); + it("should return: 'Keybord'", () => { + expect(removeLastVowel("Keyboard")).toEqual("Keybord"); + }); + + it("should return: 'Thos wh dar t fal miserbly cn achiev gretly.'", () => { + expect(removeLastVowel("Those who dare to fail miserably can achieve greatly.")).toEqual( + "Thos wh dar t fal miserbly cn achiev gretly." + ); + }); + + it("should return: 'Lov s serios mentl diseas'", () => { + expect(removeLastVowel("Love is a serious mental disease.")).toEqual("Lov s serios mentl diseas."); + }); + + it("should return: 'Gt bsy livng r gt bsy dyng'", () => { + expect(removeLastVowel("Get busy living or get busy dying.")).toEqual("Gt bsy livng r gt bsy dyng."); + }); + + it("should return: 'f yo wnt t liv hppy lif, ti t t gol, nt t peopl.'", () => { + expect(removeLastVowel("If you want to live a happy life, tie it to a goal, not to people.")).toEqual( + "f yo wnt t liv hppy lif, ti t t gol, nt t peopl." + ); }); }); diff --git a/Problems/Remove-The-Last-Vowel/solver.ts b/Problems/Remove-The-Last-Vowel/solver.ts index 66f8eb6..9c78967 100644 --- a/Problems/Remove-The-Last-Vowel/solver.ts +++ b/Problems/Remove-The-Last-Vowel/solver.ts @@ -1 +1,16 @@ -export default function removeLastVowel(): void {} +/** biome-ignore-all lint/complexity/useIndexOf: Can't use here, searching in an array*/ + +const vowels: readonly string[] = ["a", "e", "i", "o", "u"]; + +export default function removeLastVowel(text: string): string { + return text + .split(" ") + .map((str) => + [...str].reduceRight( + (preVal, curVal, curI) => + str.substring(curI) === curVal + preVal && vowels.includes(curVal.toLowerCase()) ? preVal : curVal + preVal, + "" + ) + ) + .join(" "); +} From 32ef55cf943ecdcc1c7c2de54d34aa4a9341afb2 Mon Sep 17 00:00:00 2001 From: Dennis Bauer Date: Sun, 8 Mar 2026 11:31:21 +0100 Subject: [PATCH 3/3] Finished problem --- Problems/Remove-The-Last-Vowel/README.md | 33 ++++++++++++++++++++++-- README.md | 5 ++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Problems/Remove-The-Last-Vowel/README.md b/Problems/Remove-The-Last-Vowel/README.md index c232dcd..4771fdf 100644 --- a/Problems/Remove-The-Last-Vowel/README.md +++ b/Problems/Remove-The-Last-Vowel/README.md @@ -13,13 +13,42 @@ Try to implement the solution as a **one-liner**, meaning the function should co ### Solution Idea -The Idea to solve this problem +The sentence is first split into an array of words. Each word is then processed individually. + +For every word, create a new variable that will store the modified version of that word. +Then iterate through the word from **right to left**, checking each character. + +- If the character is **not a vowel**, add it to the new word. +- If the character **is a vowel**, check whether the new word currently matches the original word up to that position. + - If it matches, it means that no vowel has been removed yet, so we **skip this vowel** (this removes the last vowel). + - If it does not match, a vowel has already been removed earlier, so we **add the vowel** to the new word. + +After processing the whole word, continue with the next word in the array. + +Finally, join the modified words back together into a sentence and return the result. --- ### [Implementation](./solver.ts) -The implementation for solving this problem +First, the sentence is split at each space `" "` to get an array of words. +Then we use `map` to process each word individually. + +For each word, we split it into characters. To keep the number of methods small, we use `[...str]` to convert the word into an array of characters. + +Next, we process this array using `reduceRight`. +We could also reverse the array and use `reduce`, but `reduceRight` saves us that extra step. + +Inside the `reduceRight` function, we check whether the substring of the original word up to the current index matches the value that is currently being built (`current + previous`). If it matches, it means that **no vowel has been removed yet**. + +- If the current character is a vowel, we skip it by returning only the previous value. +- If it is not a vowel, we return `current + previous`. + +If the substring does **not** match anymore, it means a vowel has already been removed earlier, so we simply return `current + previous`. + +After `reduceRight` finishes, we have the word without its last vowel. + +Once the `map` function has processed all words, we join the array back into a sentence using a space `" "` and return the result. --- diff --git a/README.md b/README.md index a016001..9671fab 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ This repository is about solving coding-problems. It contains famous (or not tha ## Problems -Solved: **22 problems** +Solved: **23 problems** -🟢 Easy: 16 +🟢 Easy: 17 🟠 Medium: 5 🔴 Hard: 1 @@ -38,6 +38,7 @@ Solved: **22 problems** | [Reach Exit](./Problems/Reach-Exit/README.md) | 🟢 Easy | | [One Two Skip a Few](./Problems/One-Two-Skip-A-Few/README.md) | 🟢 Easy | | [Day number of year](./Problems/Day-Number-Of-Year/README.md) | 🟢 Easy | +| [Remove the last vowel](./Problems/Remove-The-Last-Vowel/README.md) | 🟢 Easy |