Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Problems/Seven-Boom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Seven-Boom

Create a function that takes an array of numbers and for every 7 found, add one "Boom!" to your result. If no 7 is found anywhere, return "there is no 7 in the array".

## Infos which are maybe needed

If e.g there is a `77` in the array, the count of 7's needs to increase by two.

## Documentation

### Solution Idea

First, combine all numbers into a single string.
Then count how many times the digit `"7"` appears in that string.

- If the count is `0`, return that there is no `"7"`.
- If the count is greater than `0`, return `"Boom!"` repeated as many times as the digit `"7"` appears.

---

### [Implementation](./solver.ts)

First, the array is joined into a single string using `array.join("")`.
Then we split the string again with `split("")`, which results in an array containing every single digit.

Next, we use `reduce` to count how many times the digit `"7"` appears.
The reducer keeps track of the current count of sevens.

If the current value is `"7"`, we increase the counter by 1.
Otherwise, we return the counter unchanged.

Example reducer:

.reduce((count, current) => (current === "7" ? count + 1 : count), 0)

After this step, we have the total number of `"7"` digits stored in `sevenCount`.

Finally, we check the value of this counter:

- If it is `0`, we return the message that there is no `"7"`.
- If it is greater than `0`, we return `"Boom!"` repeated `sevenCount` times using:

`"Boom! ".repeat(sevenCount).trim();`

---

### Information's

This problem comes from the newsletter [Sloth Bytes](https://slothbytes.beehiiv.com).
[Post](https://slothbytes.beehiiv.com/p/how-does-google-maps-find-the-fastest-route) from February 25, 2026.
20 changes: 20 additions & 0 deletions Problems/Seven-Boom/seven-boom.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from "vitest";
import sevenBoom from "./solver";

describe("Determines the correct count of sevens in the array", () => {
it("should return one 'Boom!' for the first array", () => {
expect(sevenBoom([1, 2, 3, 4, 5, 6, 7])).toEqual("Boom!");
});

it("should return 'there is no 7 in the array' for the second array", () => {
expect(sevenBoom([8, 6, 33, 100])).toEqual("there is no 7 in the array");
});

it("should return one 'Boom' for the third array", () => {
expect(sevenBoom([2, 55, 60, 97, 86])).toEqual("Boom!");
});

it("should return three 'Boom' for the fourth array", () => {
expect(sevenBoom([7, 77, 100])).toEqual("Boom! Boom! Boom!");
});
});
9 changes: 9 additions & 0 deletions Problems/Seven-Boom/solver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function sevenBoom(array: number[]): string {
const sevenCount = array
.join("")
.split("")
.reduce((count, current) => (current === "7" ? count + 1 : count), 0);

if (sevenCount === 0) return "there is no 7 in the array";
else return "Boom! ".repeat(sevenCount).trim();
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ This repository is about solving coding-problems. It contains famous (or not tha

## Problems

Solved: **25 problems**
Solved: **26 problems**

🟢 Easy: 19
🟢 Easy: 20
🟠 Medium: 5
🔴 Hard: 1

Expand Down Expand Up @@ -41,6 +41,7 @@ Solved: **25 problems**
| [Remove the last vowel](./Problems/Remove-The-Last-Vowel/README.md) | 🟢 Easy |
| [Bingo Check](./Problems/Bingo-Check/README.md) | 🟢 Easy |
| [Missing Number](./Problems/Missing-Number/README.md) | 🟢 Easy |
| [Seven Boom!](./Problems/Seven-Boom/README.md) | 🟢 Easy |

<!-- PROBLEMS_END -->

Expand Down
Loading