Created
March 8, 2020 23:59
-
-
Save TroublesNCuddles/db5c5ef3b0fbba146363b7ab2189c79d to your computer and use it in GitHub Desktop.
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
const AVAILABLE_LETTERS = [ | |
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', | |
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' | |
]; | |
const CURRENT_STATE = [0, 0, 0, 0, 0, 0, 0]; | |
const PLATES = []; | |
const incrementCurrent = () => { | |
CURRENT_STATE[CURRENT_STATE.length - 1]++; | |
if (CURRENT_STATE[6] > 9) { | |
CURRENT_STATE[5]++; | |
CURRENT_STATE[6] = 0; | |
} | |
if (CURRENT_STATE[5] > 9) { | |
CURRENT_STATE[4]++; | |
CURRENT_STATE[5] = 0; | |
} | |
if (CURRENT_STATE[4] > 9) { | |
CURRENT_STATE[3]++; | |
CURRENT_STATE[4] = 0; | |
} | |
if (CURRENT_STATE[3] > AVAILABLE_LETTERS.length - 1) { | |
CURRENT_STATE[2]++; | |
CURRENT_STATE[3] = 0; | |
} | |
if (CURRENT_STATE[2] > AVAILABLE_LETTERS.length - 1) { | |
CURRENT_STATE[1]++; | |
CURRENT_STATE[2] = 0; | |
} | |
if (CURRENT_STATE[1] > AVAILABLE_LETTERS.length - 1) { | |
CURRENT_STATE[0]++; | |
CURRENT_STATE[1] = 0; | |
} | |
return CURRENT_STATE[0] <= 9; | |
}; | |
const generatePlates = () => { | |
while (incrementCurrent()) { | |
console.log(`${CURRENT_STATE[0]}${AVAILABLE_LETTERS[CURRENT_STATE[1]]}${AVAILABLE_LETTERS[CURRENT_STATE[2]]}${AVAILABLE_LETTERS[CURRENT_STATE[3]]}${CURRENT_STATE[4]}${CURRENT_STATE[5]}${CURRENT_STATE[6]}`) | |
} | |
}; | |
generatePlates(); |
AppiChudilko
commented
Dec 10, 2020
function generatePlate(length = 8) { let text = ""; let possible = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for (let i = 0; i < length; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; };
While the idea behind that is sound, it also fails to meet the requirements of the project. Your solution will generate a randomized plate, which is not what the project called for. The project called for the generation of all license plates that conforms to the CA DMV pattern.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment