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.
extract_trailing_characters(text, count) returns the last count characters of text. Example: extract_trailing_characters("hello_world", 5) → "world".
Logic error
count_csv_tags(tagString) returns the number of comma-separated tags in a string, returning 0 for an empty string. Example: count_csv_tags("") → 0.
Logic error
find_user_position(users, id) returns the index of the user object with matching id, or -1 if missing. Example: find_user_position([{ id: 1 }, { id: 2 }], 2) → 1.
Logic error
calculate_retry_limit(config) returns double maxRetries, defaulting to 5 if maxRetries is null or undefined. Example: calculate_retry_limit({ maxRetries: null }) → 10.
Null / Undefined
calculate_bill_with_tax(subtotal, taxRate) returns the sum of subtotal and rounded tax. Example: calculate_bill_with_tax(100, 0.15) → 115.
Type error
find_status_code(codes, target) returns the matching number from codes, or -1 if target is not in the array. Example: find_status_code([10, 0, 20], 0) → 0.
Logic error
format_invoice_number(numStr) pads a number string with leading zeroes to a length of 5. Example: format_invoice_number("42") → "00042".
Logic error
remove_item_at_index(items, index) removes the item at index and returns the shortened array. Example: remove_item_at_index(["apple", "banana", "cherry"], 1) → ["apple", "cherry"].
Logic error
has_user_by_id(users, targetId) returns true if a user with targetId exists in users. Example: has_user_by_id([{ id: 'u1' }], 'u1') → true.
Logic error
get_user_display_name(profile) extracts the user name from profile, returning "Anonymous" if profile is null or not an object. Example: get_user_display_name(null) → "Anonymous".
Null / Undefined
clamp_percentage(value) constrains value to the range 0 to 100 inclusive. Example: clamp_percentage(150) → 100.
Logic error
add_user_role(roles, newRole) appends newRole to roles and returns the updated array. Example: add_user_role(["user"], "admin") → ["user", "admin"].
Type error
prepend_item(items, newItem) returns an array with newItem prepended at the beginning. Example: prepend_item(["b"], "a") → ["a", "b"].
Type error
calculate_remaining_balance(balance, payment) subtracts payment from balance, rounded to 2 decimal places. Example: calculate_remaining_balance(1.0, 0.9) → 0.1.
Logic error
has_custom_field(payload, fieldName) returns true only if fieldName is an own property of payload, ignoring inherited prototype properties. Example: has_custom_field({}, "toString") → false.
Logic error
sanitize_phone_number(phone) strips all hyphens from a phone number string. Example: sanitize_phone_number("123-456-7890") → "1234567890".
Logic error
extract_referrer_source(queryString) returns referrer parameter ref, falling back to "organic" if ref is missing, "null", or "undefined". Example: extract_referrer_source("ref=null") → "organic".
Type error
calculate_cart_tax(cartItems) sums the tax amount across all items in a cart, returning 0 if the cart is empty. Example: calculate_cart_tax([]) → 0.
Type error
join_endpoint_path(parts) joins non-empty path segments with a single slash. Example: join_endpoint_path(["api", null, "users"]) → "api/users".
Logic error
parse_number_ids(ids) converts an array of string numbers into integers. Example: parse_number_ids(["10", "10", "10"]) → [10, 10, 10].
Type error
get_lowest_price(prices) returns the minimum price from prices, returning 0 if the list is empty. Example: get_lowest_price([]) → 0.
Logic error
is_token_expired(payload, currentTimestampMs) returns true if the JWT payload expiration (in Unix seconds) has passed relative to currentTimestampMs (in milliseconds). Example: is_token_expired({ exp: 1730592000 }, 1730591000000) → false.
Type error
get_latest_breadcrumb(breadcrumbs) returns the final item from breadcrumbs using modern indexing. Example: get_latest_breadcrumb(["home", "docs", "api"]) → "api".
Logic error
sort_prices_ascending(prices) returns a new array with numbers sorted in ascending numerical order without modifying the original array. Example: sort_prices_ascending([100, 25, 5]) → [5, 25, 100].
Logic error
format_tag_summary(tags) returns "No tags" if tags is null, undefined, or empty, returning "N tags" otherwise. Example: format_tag_summary([]) → "No tags".
Logic error
Showing 26–50 of 133 JavaScript challenges