[Algorithm]Seattle Hackers December
This content is what i did in ‘SeattleJS Hackers Code Katas[Theme: Recursion]’
1.
Given the triangle of consecutive odd numbers:
1 | 1 |
Calculate the row sums of this triangle from the row index (starting at index 1) e.g.:
1 | rowSumOddNumbers(1); // 1 |
Solution
1 | const sumNested = (arr) => { |
2.
Implement a function to calculate the sum of the numerical values in a nested list. For example :
Example
1 | sumNested([1, [2, [3, [4]]]]) => 10 |
Solution
1 | const sumNested = arr => { |
3.
In this kata, you must create a digital root function.
A digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers.
Here’s how it works:
Example
1 | digital_root(16) |
Solution
1 | function digital_root(n) { |
4.
The new “Avengers” movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 dollar bill. An “Avengers” ticket costs 25 dollars.
Vasya is currently working as a clerk. He wants to sell a ticket to every single person in this line.
Can Vasya sell a ticket to every person and give change if he initially has no money and sells the tickets strictly in the order people queue?
Return YES, if Vasya can sell a ticket to every person and give change with the bills he has at hand at that moment. Otherwise return NO.
Example
1 | tickets([25, 25, 50]) // => YES |
Solution
1 | function tickets(peopleInLine){ |