Ten days of JS is a collection of 10 problems that can be done in any order. Problems range from easy to medium. You can find all the solutions by clicking on Repl.it - I added comments directly in the solution when I thought it was necessary.
😃 Day 1 - Be happy
Write a function to determine if a number is "happy".
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.
Input: 19 Output: true
1^2 + 9^2 = 82 8^2 + 2^2 = 68 6^2 + 8^2 = 100 1^2 + 0^2 + 0^2 = 1
0️⃣ 1️⃣ Day 2 - Let's count in bits
Write a function that takes a decimal number and convert it to a binary number.
Input: 4 Ouptut: 100
➡️ Day 3 - Move zero at then end
Write a function that moves all zero from an array to the end of the array. Return the array.
Input: [2, 3, 0, 4, 3, 0, 6, 7] Output: [2, 3, 4, 3, 6, 7, 0, 0]
⏰ Day 4 - Around the clock
Given a time in string format and a number of minutes return the time given those minutes added to the base time.
You're working with a standard 12-hour clock. Output needs to match input format HH:MM.
Input: ('1:30', 30) Output: '2:00'
㊙️ Day 5 - Pig Latin
Translate the provided string to Pig Latin by following the rules below:
For words that begin with consonant sounds, the consonant before the initial vowel should be moved to the end of the word sequence and "ay" affixed. E.g "pig" = "igpay"
For words that begin with consonant clusters, the clusters should be moved to the end of the word sequence and "ay" affixed. E.g "glove" = "oveglay"
For words that begin with vowel sounds, simply add "way" to the end of the word. E.g "explain" = "explainway”
Input: 'pig' Output: 'igpay'
❗️ Day 6 - Factorial in 3 ways
Write 3 different functions to calculate the factorial of a number.
Input: 4 Output: 24
You could use the iterative approach, the recursive approach and memoization.
❌ Day 7 - Intersection
Given two sorted arrays of numbers, return an array containing all values that appear in both arrays. The numbers in the resulting array may be returned in any order.
You can assume that each array has only unique values (no duplicates within the array).
Input: [1,4,9,10,11] [2,3,4,5,8,10] Output: [4, 10]
🤘 Day 8 - String Permutation
Given a string write a function to display all the possible permutations.
input: 'abc' output: 'abc', 'acb', 'cab', 'cba', 'bac', 'bca'
➕ Day 9 - Range Sum
Given an array of 2 numbers return the cumulative sum of the two numbers and all the numbers in between. Try to find 3 different solutions.
You could use for loops, recursion and reduce.
input: [1, 9] output: 45 (1+ 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9)
💥 Day 10 - Let's Play
We have a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if our robot ends up at (0, 0) after it completes its moves.
The move sequence is represented by a string, and the character moves represents its moves. Valid moves are R (right), L (left), U (up), and D (down). If the robot returns to the origin after it finishes all of its moves, return true. Otherwise, return false.
Input: ‘DU’ Output: true