Multiple instances incrementing same value
Each tracker from makeTracker() should start at zero, so trackTwice(5, 3) returns 3 — the second tracker's own total.
Filter by language, bug pattern or difficulty
A developer asked ChatGPT to 'write a function that removes all occurrences of a specific item from an array in-place'. The AI confidently provided this code. It passes the basic test removeAll([1, 2, 3], 2), but fails in production.
Logic error
An intern asked Copilot to 'write a function that returns True if any two numbers in the list add up to the target'. The AI generated this beautifully readable code. It correctly returns True for ([1, 2, 3], 5) and False for ([1, 2, 3], 10). But it contains a fatal flaw.
Logic error
ChatGPT was asked to write a function that formats an array of names into an English list (e.g. ['A', 'B', 'C'] -> 'A, B and C'). The function works perfectly the first time you call it. But the developer who used it noticed their data was disappearing.
Other
append_to_list(val) should create a new list with val if no list is provided. test_append() calls it twice with 1 and 2.
Scope error
parseAll(strings) should take an array of numeric strings and return an array of integers.
Type error
make_multipliers() returns a list of 3 functions multiplying by 0, 1, and 2. test_multipliers() calls each with 10 and returns the results.
Scope error
sortNumbers(arr) should sort an array of numbers from smallest to largest.
Logic error
total_values(data) should add up a dictionary's values, so total_values({'a': 1, 'b': 2}) returns 3.
Other
sorted_names(names) should return the names in alphabetical order, so sorted_names(["b","a"]) returns ["a","b"].
Other
The function copies a grid, edits the copy, then reports the ORIGINAL's first cell — which should be unchanged. For [[1,2],[3,4]] it returns 1.
Other
addRounded(a, b) should add two numbers and return the result rounded to two decimal places, as a number. addRounded(1, 2) is 3.
Other
stripDashes(text) should remove every dash, so stripDashes("a-b-c") returns "abc".
Other
isAvailable(item) should be true only when the item is in stock AND not discontinued.
Logic error
safe_ratio(a, b) should return True when a / b is greater than 1, and False when b is zero rather than crashing.
Logic error
largest_gap(nums) should return the biggest jump between consecutive values in an ascending list, so largest_gap([1, 5, 6]) returns 4.
Logic error
all_positive(nums) should return True only when EVERY number is greater than zero.
Logic error
percentChange(oldValue, newValue) should report the change as a percentage of the old value. Going from 100 to 150 is +50.
Logic error
max_window_sum(nums, k) should return the largest sum of any k consecutive numbers. max_window_sum([1,2,3,10], 2) is 13.
Off-by-one
count_in_range(nums, low, high) counts values between low and high INCLUSIVE, so count_in_range([1,2,3], 1, 3) returns 3.
Off-by-one
chunk(items, size) should split a list into groups of size, keeping any short final group. chunk([1,2,3,4,5], 2) gives [[1,2],[3,4],[5]].
Off-by-one
last_char(text) should return the final character, so last_char("hello") returns "o".
Off-by-one
joinWithDash(words) should join words with dashes between them, so joinWithDash(["a","b"]) returns "a-b".
Off-by-one
total_score(scores, names) should add up the scores for the named players, treating anyone without a score as 0.
Null / Undefined
pageItems(items, page, size) returns one page of results. Pages are numbered from 1, so pageItems([1,2,3,4,5,6], 1, 3) gives [1,2,3].
Off-by-one