Skip to content

#254 Keyboard Mistakes

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

254 Keyboard Mistakes

Your task is to correct the errors in the digitized text. You only have to handle the following mistakes:

A is misinterpreted as 4

S is misinterpreted as 5

O is misinterpreted as 0

I is misinterpreted as 1

The test cases contain numbers only by mistake.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/254 Keyboard Mistakes.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.

//Your task is to correct the errors in the digitized text. You only have to handle the following mistakes:
//A is misinterpreted as 4
//S is misinterpreted as 5
//O is misinterpreted as 0
//I is misinterpreted as 1
//The test cases contain numbers only by mistake.
function keyboardMistakes(str) {
    return str
        .replaceAll("4", "A")
        .replaceAll("5", "S")
        .replaceAll("0", "O")
        .replaceAll("1", "I")
}
import { assertEquals } from '../testHelper.js';
assertEquals(keyboardMistakes("MUB45H1R"), "MUBASHIR")
assertEquals(keyboardMistakes("DUBL1N"), "DUBLIN")
assertEquals(keyboardMistakes("51NG4P0RE"), "SINGAPORE")
assertEquals(keyboardMistakes("P4K15T4N"), "PAKISTAN")
assertEquals(keyboardMistakes("P4R15"), "PARIS")

Clone this wiki locally