Write Up Code Wars— Life Path Number Using JavaScript

Handhika Yanuar Pratama
2 min readFeb 11, 2021

Code Wars is best platform for learning algorithm from programming language, here I want to write the solution for ‘Life Path Number’ challenge using JavaScript. When it was written, the challenge is still in kyu 7.

Question

A person's Life Path Number is calculated by adding each individual number in that person's date of birth, until it is reduced to a single digit number.Complete the function that accepts a date of birth (as a string) in the following format: "yyyy-mm-dd". The function shall return a one digit integer between 1 and 9 which represents the Life Path Number of the given date of birth.You do not need to check that the input is correct format, you can assume that it will always be a valid date (as a string) with given format.

Example

For example, Albert Einstein's birthday is March 14, 1879 ("1879-03-14"). The calculation of his Life Path Number would look like this:year  :  1 + 8 + 7 + 9 = 2  -->  2 + 5 = 7
month : 0 + 3 = 3
day : 1 + 4 = 5
result: 7 + 3 + 5 = 15 --> 1 + 5 = 6

I hope you try this challenge first, because it was a fun challenge. You will learn a lot with recursive array.

Here is my solution

Too long answer right, but it’s okay. I am still beginner, here is the best solution that I found, using regex

Only one line right? 😥

Don’t ever stop trying!!!, Have a Nice Code

--

--