# Finding life path number based on a date of birth in JavaScript

JavascriptWeb DevelopmentFront End Technology

## Life Path Number

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.

## Problem

We are required to write a JavaScript function that takes in a date in “yyyy-mm-dd” format and returns the life path number for that date of birth.

For instance,

if the date is: 1999-06-10

year : 1 + 9 + 9 + 9 = 28 → 2 + 8 = 10 → 1 + 0 = 1
month : 0 + 6 = 6
day : 1 + 0 = 1
result: 1 + 6 + 1 = 8

## Example

Following is the code −

Live Demo

const date = '1999-06-10';
const findLifePath = (date = '') => {
const sum = (arr = []) => {
if(arr.length === 1){
return +arr
};
let total = arr.reduce((acc, val) => acc + val);
if (total < 10){
};
return sum(String(total).split("").map(Number));
};
let [year, month, day] = date.split("-")
year = sum(String(year).split("").map(Number));
month = sum(String(month).split("").map(Number));
day = sum(String(day).split("").map(Number));
return sum([year,month,day]);
};
console.log(findLifePath(date));

## Output

Following is the console output −

8