Loading 3 items returns only one
loadAll(ids) loads every id and returns all the results in order. Example: await loadAll([1, 2, 3]) → [10, 20, 30].
Explore 133 JavaScript challenges. Filter by bug pattern or difficulty.
filter_valid_orders(orderIds) filters an array of order IDs and returns only those matching the pattern "ORD-XXXX". Example: filter_valid_orders(["ORD-1001", "ORD-1002"]) → ["ORD-1001", "ORD-1002"].
Scope error
filter_valid_inventory(items) keeps all items that have a defined count property, including zero. Example: filter_valid_inventory([{ id: 1, count: 0 }]) → [{ id: 1, count: 0 }].
Logic error
calculate_discounted_total(subtotal, promoPercent) applies promoPercent to subtotal, falling back to 15% only if promoPercent is missing or undefined. Example: calculate_discounted_total(100, 0) → 100.
Logic error
totalScore(rounds) adds up the points from every round. Example: totalScore([10, 20, 30]) → 60.
Off-by-one
parsePrice(text) reads a price that may have commas, like "1,250.50". Example: parsePrice("1,250.50") → 1250.5.
Type error
getStatus(code) wraps an HTTP status code in an object. Example: getStatus(200) → { ok: true }.
Other
isPalindrome(word) returns true if the word reads the same backwards, ignoring capitals. Example: isPalindrome("Racecar") → true.
Logic error
inStock(items, name) returns true if the product is in the list. Example: inStock(["pen", "ink"], "pen") → true.
Logic error
sumAll(nums) adds up an array of numbers. Example: sumAll([5, 6, 7]) → 18.
Type error
countSettings(settings) returns how many settings an object has. Example: countSettings({ theme: "dark", lang: "en" }) → 2.
Null / Undefined
digitSum(n) adds up the digits of a number. Example: digitSum(123) → 6.
Type error
checkPin(typed, saved) compares a PIN typed in a form, as text, with a saved PIN stored as a number. Example: checkPin("1234", 1234) → true.
Type error
dayType(day) returns "weekend" for Saturday and Sunday, and "weekday" for any other day. Example: dayType("Saturday") → "weekend".
Logic error
countWords(words) counts how many times each word appears. Example: countWords(["a", "b", "a"]) → { a: 2, b: 1 }.
Null / Undefined
highestPrice(prices) returns the biggest price. Example: highestPrice([3, 7, 2]) → 7.
Logic error
splitTeams(players) puts each player in team 0 or team 1. Example: splitTeams([{ name: "a", team: 0 }, { name: "b", team: 1 }]) → [["a"], ["b"]].
Other
countPositives(nums) counts the numbers above zero. Example: countPositives([3, -1, 4]) → 2.
Type error
hasNegative(nums) returns true if any number is negative. Example: hasNegative([5, -3, 8]) → true.
Logic error
formatDate(isoDate) turns a date like "2024-03-15" into "15/3/2024". Example: formatDate("2024-03-15") → "15/3/2024".
Off-by-one
lastSong(playlist) returns the last song. Example: lastSong(["Intro", "Hook", "Outro"]) → "Outro".
Off-by-one
withShipping(prices) adds 5 for shipping to every price. Example: withShipping([10, 20]) → [15, 25].
Null / Undefined
An AI assistant wrote this for a classic interview question. removeAll(arr, item) removes every copy of item from the array. Example: removeAll([1, 2, 2, 3], 2) → [1, 3].
Logic error
An AI assistant wrote formatNames(names), which turns a list into English, like ["A", "B", "C"] → "A, B and C". It must not change the list it is given. test_format checks that. Example: test_format(["Alice", "Bob", "Charlie"]) → "Alice, Bob and Charlie".
Other
parseAll(strings) turns a list of number strings into numbers. Example: parseAll(["10", "10", "10"]) → [10, 10, 10].
Type error
sortNumbers(arr) sorts numbers from smallest to largest. Example: sortNumbers([10, 2, 30]) → [2, 10, 30].
Logic error
Showing 51–75 of 133 JavaScript challenges