Skip to content

#025 Buggy Code0

Adam Kubiś edited this page Oct 28, 2026 · 1 revision

025 Buggy Code0

The challenge is to try and fix this buggy code, given the inputs true and false.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/025 Buggy Code0.js"

Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.

Current implementation and tests

This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.

//The challenge is to try and fix this buggy code, given the inputs true and false.
function has_bugs(buggy_code) {
	if (buggy_code) {
		return 'sad days';
	} else {
		return "it's a good day";
	}
}
import * as Test from '../testHelper.js';
Test.assertEquals(has_bugs(true), "sad days")
Test.assertEquals(has_bugs(false), "it's a good day")

Historical reference notes

Cross-language explanation preserved from the study materials

Reference file: #025 Buggy Code0.txt. These older notes use a separate numbering scheme and may describe C# code, external diagrams or benchmark timings. They are reference material, not measured JavaScript performance. The current implementation and assertions above are authoritative.

# [Buggy Code](https://edabit.com/challenge/9p6Lfwu8tYazvaHGe)
Published by [Mubashir Hassan](https://edabit.com/user/T6iBEE2jp7f7iEF2P)

bugs language_fundamentals noC#equivalent

The challenge is to try and fix this buggy code, given the inputs `true` and `false`. See the examples below for the expected output.

`has_bugs(true) ➞ "sad days"`

`has_bugs(false) ➞ "it's a good day"`

Don't overthink this challenge (look at the syntax and correct it).

### Time Complexity:
The space complexity is _O(1)_. The function does a single boolean check and returns one of two constant results. No loops or recursion, so best/worst/average are constant.

### Space Complexity:
The space complexity is also _O(1)_. No allocations or data structures proportional to input size. (The returned strings are compile-time interned literals, so they don’t incur per-call heap allocation; even if they did, their size is constant.

![flowchart](https://lh3.googleusercontent.com/pw/AP1GczMPuQ4q6TV-0bojhn3JYGudPJNylaolanwvlRd_UTjmRWtJvnOP8ORSkKHtLMTMKbGgB0H6MItO-l34uE9Z1TK1Z3yPUhnukom-kMnzUa9_WHPYLSXty1StIi9cA6DbP3Vjawgh4Jlj8AcnJQWD-DJS=w754-h911-s-no-gm?authuser=0)

Clone this wiki locally