Code Challenges
Solve problems, earn XP, and level up your skills.
Palindrome Check
Write a function `isPalindrome(str)` that returns `true` if the string reads the same forwards and backwards (ignore case), `false` otherwise. Example: isPalindrome('racecar') → true isPalindrome('hello') → false isPalindrome('Madam') → true
FizzBuzz
Write a function `fizzBuzz(n)` that returns an array of strings for numbers 1 to n: - "Fizz" for multiples of 3 - "Buzz" for multiples of 5 - "FizzBuzz" for multiples of both - The number as a string otherwise Example: fizzBuzz(5) → ["1", "2", "Fizz", "4", "Buzz"]
Remove Duplicates
Write a function `removeDuplicates(arr)` that returns a new array with all duplicate values removed, keeping the first occurrence. Example: removeDuplicates([1,2,2,3,3,4]) → [1,2,3,4] removeDuplicates(['a','b','a','c']) → ['a','b','c']
Fibonacci Sequence
Write a function `fibonacci(n)` that returns the nth Fibonacci number (0-indexed). The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, ... Example: fibonacci(0) → 0 fibonacci(1) → 1 fibonacci(6) → 8 fibonacci(10) → 55
Flatten Array
Write a function `flatten(arr)` that takes a nested array and returns a flat (1D) array. Example: flatten([1, [2, 3], [4, [5]]]) → [1, 2, 3, 4, 5] flatten([[1, 2], [3, [4, [5]]]]) → [1, 2, 3, 4, 5]
Anagram Check
Write a function `isAnagram(str1, str2)` that returns `true` if the two strings are anagrams of each other (same letters, different order), ignoring case and spaces. Example: isAnagram('listen', 'silent') → true isAnagram('hello', 'world') → false isAnagram('Astronomer', 'Moon starer') → true
Chunk Array
Write a function `chunk(arr, size)` that splits an array into chunks of a given size. Example: chunk([1,2,3,4,5], 2) → [[1,2],[3,4],[5]] chunk([1,2,3,4,5,6], 3) → [[1,2,3],[4,5,6]]