Last active
February 1, 2022 00:53
-
-
Save mihirs16/5715a43d34dda545e0d9dcf970ac4d43 to your computer and use it in GitHub Desktop.
Generates a random ID for MongoDB mock-primary key.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateAssignmentID() { | |
var id_elem = []; | |
var dateObj = new Date(); | |
function convertToString(id_elem) { | |
return id_elem.toLocaleString('en-US', { | |
minimumIntegerDigits: 2, | |
useGrouping: false | |
}); | |
} | |
id_elem[0] = convertToString(dateObj.getDate()); | |
id_elem[1] = convertToString(dateObj.getMonth()); | |
id_elem[2] = convertToString(dateObj.getFullYear()).slice(2, 4); | |
id_elem[3] = convertToString(Math.floor(Math.random() * 26)); | |
id_elem[4] = convertToString(Math.floor(Math.random() * 26)); | |
id_elem[5] = convertToString(Math.floor(Math.random() * 26)); | |
return id_elem.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment