Top 50 JavaScript Coding Challenges for Beginners
Top 50 JavaScript Coding Challenges for Beginners
Reverse a String: Write a function that reverses a given string.
- Input:
"hello"
- Output:
"olleh"
Check for Palindromes: Create a function to check if a string is a palindrome.
- Input:
"racecar"
- Output:
true
Factorialize a Number: Write a function to find the factorial of a given number.
- Input:
5
- Output:
120
Find the Longest Word in a String: Create a function to find the length of the longest word in a sentence.
- Input:
"The quick brown fox jumped over the lazy dog"
- Output:
6
Title Case a Sentence: Write a function that converts a sentence to title case.
- Input:
"i am learning javascript"
- Output:
"I Am Learning JavaScript"
Find the Largest Numbers in Arrays: Create a function that returns an array containing the largest number from each sub-array.
- Input:
[[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39]]
- Output:
[5, 27, 39]
Confirm the Ending: Write a function to check if a string ends with a given target string.
- Input:
("Bastian", "n")
- Output:
true
Repeat a String Repeat a String: Create a function that repeats a string n
times.
- Input:
("abc", 3)
- Output:
"abcabcabc"
Truncate a String: Write a function to truncate a string if it is longer than a given maximum string length.
- Input:
("A-tisket a-tasket A green and yellow basket", 8)
- Output:
"A-tisket..."
Finders Keepers: Create a function that looks through an array and returns the first element that passes a given test.
- Input:
([1, 3, 5, 8, 9, 10], num => num % 2 === 0)
- Output:
8
Boo Who: Write a function to check if a value is classified as a boolean primitive.
- Input:
true
- Output:
true
Title Case a Sentence: Write a function to convert the first letter of each word in a sentence to uppercase.
- Input:
"I'm a little tea pot"
- Output:
"I'm A Little Tea Pot"
Slice and Splice: Create a function that combines two arrays by inserting the second array into the first at a given index.
- Input:
([1, 2, 3], [4, 5], 1)
- Output:
[1, 4, 5, 2, 3]
Falsy Bouncer: Write a function that removes all falsy values from an array.
- Input:
[7, "ate", "", false, 9]
- Output:
[7, "ate", 9]
Where do I Belong: Create a function that returns the lowest index at which a value should be inserted into an array.
- Input:
([40, 60], 50)
- Output:
1
Mutations: Write a function to check if a string contains all the letters of another string.
- Input:
["hello", "hey"]
- Output:
false
Chunky Monkey: Create a function that splits an array into groups of the specified size.
- Input:
([1, 2, 3, 4, 5, 6], 2)
- Output:
[[1, 2], [3, 4], [5, 6]]
Sum All Numbers in a Range: Write a function that returns the sum of all numbers in a given range.
- Input:
[1, 4]
- Output:
10
Seek and Destroy: Create a function that removes all elements from an array that are of the specified values.
- Input:
([1, 2, 3, 1, 2, 3], 2, 3)
- Output:
[1, 1]
Wherefore art thou: Write a function to find matching objects in an array.
- Input:
[{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }], { last: "Montague" }
- Output:
[{ first: "Romeo", last: "Montague" }]
Spinal Tap Case: Create a function that converts a string to spinal case.
- Input:
"This Is Spinal Tap"
- Output:
"this-is-spinal-tap"
Pig Latin: Write a function to translate a string into Pig Latin.
- Input:
"california"
- Output:
"aliforniacay"
Search and Replace: Create a function to perform a search and replace on a sentence using the provided arguments.
- Input:
("He is Sleeping on the couch", "Sleeping", "sitting")
- Output:
"He is Sitting on the couch"
DNA Pairing: Write a function to pair the DNA strands.
- Input:
"GCG"
- Output:
[['G', 'C'], ['C', 'G'], ['G', 'C']]
Missing letters: Create a function to find the missing letter in the passed letter range.
- Input:
"abce"
- Output:
"d"
Sorted Union: Write a function that returns a new array of unique values in the order of the original provided arrays.
- Input:
([1, 3, 2], [5, 2, 1, 4], [2, 1])
- Output:
[1, 3, 2, 5, 4]
Convert HTML Entities: Create a function that converts characters such as &
, <
, >
, "
, and '
into their corresponding HTML entities.
- Input:
"Dolce & Gabbana"
- Output:
"Dolce & Gabbana"
Sum All Odd Fibonacci Numbers: Write a function that returns the sum of all odd Fibonacci numbers less than or equal to a given number.
- Input:
10
- Output:
10
Sum All Primes: Create a function to sum all prime numbers up to and including a given number.
- Input:
10
- Output:
17
Smallest Common Multiple: Write a function to find the smallest common multiple of the provided parameters.
- Input:
[1, 5]
- Output:
60
Drop it: Create a function that removes elements from an array until the function returns true.
- Input:
([1, 2, 3], n => n >= 3)
- Output:
[3]
Steamroller: Write a function to flatten a nested array.
- Input:
[1, [2], [3, [[4]]]]
- Output:
[1, 2, 3, 4]
Binary Agents: Create a function that translates a binary string into English.
- Input:
"01000001 01110010"
- Output:
"Ar"
Everything Be True: Write a function to check if all elements in a collection are true.
- Input:
[{ name: "John", active: true }, { name: "Doe", active: false }]
- Output:
false
Arguments Optional: Create a function that returns the sum of two arguments. If only one argument is provided, return a function that expects one argument and returns the sum.
- Input:
2, 3
- Output:
5
Make a Person: Write a function to create a person object with methods to get and set the person’s name.
- Input:
("John", "Doe")
- Output:
{ getFirstName: Function, getLastName: Function, setFirstName: Function, setLastName: Function }
Map the Debris: Create a function that returns a new array with the orbital period of each satellite.
- Input:
[{ name: "sputnik", avgAlt: 35873.5553 }]
- Output:
[{ name: "sputnik", orbitalPeriod: 86400 }]
Pairwise: Write a function that returns the indices of the array elements that add up to the specified target.
- Input:
([1, 4, 2, 3, 0, 5], 7)
- Output:
[1, 3]
Implement bubble sort: Create a function that implements the bubble sort algorithm.
- Input:
[5, 3, 8, 2, 1, 4]
- Output:
[1, 2, 3, 4, 5, 8]
Selection Sort: Write a function to perform selection sort on an array.
- Input:
[5, 3, 8, 2, 1, 4]
- Output:
[1, 2, 3, 4, 5, 8]
Insert Sort: Create a function that implements the insertion sort algorithm.
- Input:
[5, 3, 8, 2, 1, 4]
- Output:
[1, 2, 3, 4, 5, 8]
Quick Sort: Write a function to perform quick sort on an array.
- Input:
[5, 3, 8, 2, 1, 4]
- Output:
[1, 2, 3, 4, 5, 8]
Merge Sort: Create a function that implements the merge sort algorithm.
- Input:
[5, 3, 8, 2, 1, 4]
- Output:
[1, 2, 3, 4, 5, 8]
Binary Search: Write a function to perform binary search on a sorted array.
- Input:
[1, 2, 3, 4, 5, 8], 4
- Output:
3
Recursive Fibonacci: Create a function to calculate the nth Fibonacci number using recursion.
- Input:
10
- Output:
55
Flatten Arrays: Write a function that flattens a nested array.
- Input:
[1, [2, [3, [4]], 5]]
- Output:
[1, 2, 3, 4, 5]
Sum All Evens: Create a function that sums all even numbers in an array.
- Input:
[1, 2, 3, 4, 5, 6]
- Output:
12
Count Vowels: Write a function to count the number of vowels in a string.
- Input:
"hello"
- Output:
2
Anagram Checker: Create a function that checks if two strings are anagrams.
- Input:
("listen", "silent")
- Output:
true
Palindrome Checker: Write a function to check if a number is a palindrome.
- Input:
121
- Output:
true
Top 50 JavaScript Coding Challenges for Beginners