[JS Practice] Sum of two array elements equals to target

Title :

Sum of two array elements equals to target

Description:

Write a function that takes an array of numbers (integers for the tests) and a target number. It should find two different items in the array that, when added together, give the target value. The indices of these items should then be returned in an array like so: [index1, index2].

The input will always be valid (numbers will be an array of length 2 or greater, and all of the items will be numbers; target will always be the sum of two different items from that array).

Example

twosum([1,2,3], 4); // must return [0, 2]

Continue reading

[JS Practice] Christmas day

Title :

Christmas day

Description:

Sometimes it’s useful to know on which day of week the holly holiday will occur.
But just don’t limit ourselves to this year and write a function which consumes a Christmas date and outputs a name of weekday.

Example

findOutChristmasWeekday('2013 12 25') // returns 'Wednesday'

Only valid Christmas dates will be passed to the function.

Date parameter could be a string or a Date object. If it’s a string here are possible date parameter formats:

'2013 12 25'
'12 25 2013'
'25 December 2013'

Note: calendar used in the kata is Gregorian.

Continue reading

[JS Practice] Boiled Eggs

Title :

Multiplication table

Description:

You are the greatest chef on earth. No one boils eggs like you! Your restaurant is always full of guests, who love your boiled eggs. But when there is a greater order of boiled eggs, you need some time, because you have only one pot for your job. How much time do you need?

Your Task

Implement a function, which takes a non-negative integer, representing the number of eggs to boil. It must return the time in minutes (integer), which it takes to have all the eggs boiled.

Rules

  • you can put at most 8 eggs into the pot at once
  • it takes 5 minutes to boil an egg
  • we assume, that the water is boiling all the time (no time to heat up)
  • for simplicity we also don’t consider the time it takes to put eggs into the pot or get them out of it

Example

cookingTime(0); // must return 0
cookingTime(5); // must return 5
cookingTime(10); // must return 10
cookingTime(16); // must return 10

Continue reading