-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
32 lines (30 loc) · 829 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
*
* @param {ISODateString} date
*/
function generateId(date) {
const numericArray = new Array();
var temp = 0;
date
.split("T")[0]
.split("-")
.forEach((ele) => numericArray.push(parseInt(ele))); // split the dateTime string into parts and sum them
date
.split("T")[1]
.split(":")
.forEach((ele) => numericArray.push(parseFloat(ele)));
var id = numericArray.reduce(reducer);
// log the new generated id, substr can be used to change the length of numberic ID
return id.toString().replace(".", "").substr(1, 6);
}
/**
*
* @param {number} accumulator - each element of the array
* @param {number} currentValue - any additional vallue to be added
*/
function reducer(accumulator, currentValue) {
return accumulator + currentValue;
}
module.exports = {
generate: generateId,
};