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.
sameOrder(a, b) returns true when two arrays hold the same values in the same order. Example: sameOrder([1, 2], [1, 2]) → true.
Type error
isValidAge(input) checks the age typed in a form. A blank field is not valid. Example: isValidAge("25") → true, isValidAge("") → false.
Type error
shout(text) returns the text in capitals with an exclamation mark. Example: shout("hi") → "HI!".
Other
initialize_buckets(count, firstItem) creates count independent buckets and adds firstItem to bucket 0 only. Example: initialize_buckets(2, 'a') → [['a'], []].
Scope error
safe_parse_token_payload(rawToken) parses a JSON token payload string, returning null if the string is invalid JSON. Example: safe_parse_token_payload("invalid{") → null.
Type error
sort_numbers_ascending(numbers) sorts numbers in ascending order using a custom comparator. Example: sort_numbers_ascending([10, 2, 5, 1]) → [1, 2, 5, 10].
Logic error
deduplicate_users_by_id(users) removes duplicate user objects sharing the same id. Example: deduplicate_users_by_id([{ id: 1 }, { id: 1 }]) → [{ id: 1 }].
Logic error
parse_strict_integer(valStr) parses a string strictly as an integer, returning NaN if it contains non-numeric trailing characters. Example: parse_strict_integer('100px') → NaN.
Type error
update_grid_cell(rows, cols, r, c, val) creates a 2D zero-filled grid of size rows × cols and updates only the cell at row r, column c. Example: update_grid_cell(2, 2, 0, 0, 99) → [[99, 0], [0, 0]].
Scope error
pop_with_fallback(items) removes and returns the last element from items, returning -1 only if items was empty. Example: pop_with_fallback([0]) → 0.
Logic error
are_all_items_in_stock(items) returns true only if items contains at least one item and every item is in stock. Example: are_all_items_in_stock([]) → false.
Logic error
parse_user_age(ageStr) parses an age string into a number, returning null for empty or non-numeric strings. Example: parse_user_age("") → null.
Type error
is_valid_quantity(qty) returns true if qty represents a positive whole integer, accepting both numbers and numeric strings. Example: is_valid_quantity("5") → true.
Type error
discard_oldest_log(logs) returns a new array with the first log removed, without mutating logs. Example: discard_oldest_log(["a", "b", "c"]) → ["b", "c"].
Logic error
flatten_nested_categories(categories) flattens a deeply nested array of category names into a single flat array. Example: flatten_nested_categories([1, [2, [3, 4]]]) → [1, 2, 3, 4].
Logic error
protect_nested_config(config, newPort) prevents mutating nested configuration properties on config. Example: protect_nested_config({ database: { port: 5432 } }, 9999) → 5432.
Scope error
is_admin_query_active(queryParams) checks if isAdmin is true, handling both boolean and string "true" values. Example: is_admin_query_active({ isAdmin: "false" }) → false.
Type error
evaluate_access_tier(user) returns "Privileged" if user.role is "admin", returning "Standard" otherwise. Example: evaluate_access_tier({ role: "guest" }) → "Standard".
Logic error
sort_names_alphabetical(names) sorts strings in case-insensitive alphabetical order. Example: sort_names_alphabetical(["zebra", "apple", "Banana"]) → ["apple", "Banana", "zebra"].
Logic error
truncate_coordinate(val) removes the fractional digits of val, rounding toward zero. Example: truncate_coordinate(-1.7) → -1.
Logic error
sum_numbers_in_list(numbers) calculates the sum of all numbers in an array. Example: sum_numbers_in_list([10, 20, 30]) → 60.
Type error
generate_index_range(length) generates an array of sequential integers from 0 to length - 1. Example: generate_index_range(3) → [0, 1, 2].
Logic error
drop_first_item(items) returns a new array containing all elements except the first. Example: drop_first_item(["a", "b", "c"]) → ["b", "c"].
Logic error
create_safe_redirect_url(targetUrl) encodes targetUrl as a query parameter in a redirect link. Example: create_safe_redirect_url("https://example.com/oauth?code=123") → "https://api.com?redirect=https%3A%2F%2Fexample.com%2Foauth%3Fcode%3D123".
Logic error
get_max_score(scores) returns the highest score from scores, returning 0 if the array is empty. Example: get_max_score([]) → 0.
Logic error
Showing 1–25 of 133 JavaScript challenges