initial commit
This commit is contained in:
38
src/utils/utils.ts
Normal file
38
src/utils/utils.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
const randomChars = () => {
|
||||
const uppercaseAsciiStart = 65;
|
||||
const letterIndex = Math.floor(Math.random() * 26);
|
||||
const letter = String.fromCharCode(uppercaseAsciiStart + letterIndex);
|
||||
|
||||
return letter;
|
||||
};
|
||||
|
||||
const generateNumberPlate = () => {
|
||||
const numberPlateLetters = new Array(4);
|
||||
const characters: string[] = [];
|
||||
for (let index = 0; index <= numberPlateLetters.length; index++) {
|
||||
const letter = randomChars();
|
||||
characters.push(letter);
|
||||
}
|
||||
const number = Math.floor(Math.random() * 99);
|
||||
characters.splice(2, 0, number + " ");
|
||||
const numberPlate = characters.join("");
|
||||
|
||||
return numberPlate;
|
||||
};
|
||||
|
||||
export const generateNumberPlateList = (numberofSightings = 5) => {
|
||||
const numberPlates = [];
|
||||
|
||||
for (let i = 0; i <= numberofSightings; i++) {
|
||||
numberPlates.push(generateNumberPlate());
|
||||
}
|
||||
|
||||
return numberPlates;
|
||||
};
|
||||
|
||||
export const formatNumberPlate = (plate: string) => {
|
||||
const splittedPlate = plate?.split("");
|
||||
splittedPlate?.splice(4, 0, " ");
|
||||
const formattedPlate = splittedPlate?.join("");
|
||||
return formattedPlate;
|
||||
};
|
||||
Reference in New Issue
Block a user