22 challenges match these filters
sorted_names(names) should return the names in alphabetical order, so sorted_names(["b","a"]) returns ["a","b"].
Other
last_char(text) should return the final character, so last_char("hello") returns "o".
Off-by-one
sumAll(nums) should add up every number in the array, so sumAll([1, 2, 3]) returns 6.
Off-by-one
middle_item(items) should return the middle element, so middle_item([1, 2, 3]) returns 2.
Type error
attempts_until_success(n) retries until the nth attempt succeeds and returns the number of tries, so attempts_until_success(3) returns 3.
Infinite loop
stepsToExceed(limit) counts how many times you must double 1 before passing limit, so stepsToExceed(8) returns 4.
Infinite loop
last_even(nums) should return the last even number, or -1 if there are none. last_even([1, 3]) should return -1.
Scope error
getName(id) should resolve to the loaded user's name, so getName(1) gives "user1".
Async race condition
shout(text) should return the text in uppercase, so "hello" becomes "HELLO".
Other
capitalize(word) should upper-case the first letter, so "debug" becomes "Debug".
Off-by-one
count_words(text) should count the words in a string, however much whitespace separates them.
Logic error
average(nums) should return the mean of a list of numbers, including any fractional part.
Type error
qualifiesForFreeShipping(total) should return true when the order total is 50 or more — spending exactly 50 qualifies.
Logic error
firstItemName(items) should return the name of the first item, or "None" when the list is empty.
Null / Undefined
firstChunk(arr, size) should return the first `size` items of an array, so firstChunk([1,2,3,4,5], 3) gives [1,2,3].
Off-by-one
get_setting(config, key) should return the value for a key, or the string "default" when that key isn't present.
Null / Undefined
calculateTotal(items) should add up the price of every item and return the total, e.g. two items at 10 and 20 gives 30.
Type error
isEven(n) should return true if n is even, false otherwise.
Logic error
can_checkout(cart_total, has_valid_payment) should return True only when the cart has items AND payment is valid.
Logic error
format_price(amount) should return the amount formatted as a price string, e.g. format_price(5) -> "$5".
Type error
getUserCity(user) should return the user's city, or "Unknown" if the user has no address on file.
Null / Undefined
sum_range(n) should return the sum of all integers from 1 to n, inclusive.
Off-by-one