- Disclaimer: This repo was generated with ChatGPT, so it might contain silly but very confident bullsh*t.
This repo is a set of beginner-friendly programming puzzles. Each puzzle contains some data that you need to process and output the result.
You need NodeJS and git installed (please google this or ask ChatGPT on how to install it).
- To clone the repo do:
git clone https://github.com/vicnaum/beginner-coding-puzzles.git
- To install packages do:
npm install
or yarn
(depending on which package manager you prefer)
Each puzzle must be solved within its corresponding js file, for example:
Puzzle 1 must be solved in puzzle1.js
file.
Each file has a puzzle()
function which receives the input and should return some output.
You need to put your code inside this function to process the input and return correct output.
You can run the tests for each puzzle with mocha:
npx mocha puzzle1.js
It will run a bunch of test cases and tell you which are correct and which are not.
Test cases are in tests
folder in JSON format.
You're organizing a bake sale and you want to keep track of how much money you've made. Write a function that accepts a list of the prices of all the items that were sold and returns the total amount of money that was made.
You're writing a program to help you study for a spelling test. Write a function that accepts a list of words and returns the number of words that have the vowel "a" in them.
Hint: the function should return 0 if the input list is empty or if there are no words in the input list that have the vowel "a" in them
You're playing a game where you have to guess the highest number. Write a function that accepts a list of numbers and returns the largest number in the list.
Hint: the function should return the smallest possible number (e.g., -infinity or the smallest possible integer value) if the input list is empty
You're making a list of all the long-named animals that live in the zoo. Write a function that accepts a list of animal names and returns a new list containing only the names of animals that have at least five letters in their name.
Hint: the function should return an empty list if the input list is empty or if all the words in the input list have fewer than five letters
You're organizing a scavenger hunt and you want to make a list of all the odd-numbered items that you need to find. Write a function that accepts a list of numbers and returns a new list containing only the odd numbers from the original list.
Hint: the function should return an empty list if the input list is empty or if there are no odd numbers in the input list
You're writing a program to help you organize your books. Write a function that accepts a list of book titles and returns a new list containing only the titles of books that start with a capital letter.
Example: if the input list is ["The Cat in the Hat", "Moby-Dick", "a Tale of Two Cities"], the output should be ["The Cat in the Hat", "Moby-Dick"]
Hint: the function should return an empty list if the input list is empty or if there are no words in the input list that start with a capital letter
You're making a word puzzle where you have to fill in the vowels in a sentence. Write a function that accepts a string and returns the string with all the vowels removed, so that you can fill them in yourself.
Hint: the function should return an empty string if the input string is empty or if it contains no vowels
You're organizing a raffle and you want to find the average price of all the prizes. Write a function that accepts a list of prize values and returns the average value of all the prizes.
You're making a word puzzle where you have to unscramble words. Write a function that accepts a string and returns a new string with all the words in the original string reversed (i.e., "Hello world" becomes "olleH dlrow").
You're writing a program to help you learn about prime numbers. Write a function that accepts a list of numbers and returns a new list containing only the numbers that are prime (i.e., divisible only by 1 and themselves).