Created
March 10, 2020 13:07
-
-
Save kdssoftware/dc5dec449579763838844109ec32ab48 to your computer and use it in GitHub Desktop.
Used for class rooms, Only uses this format: 1 or 2 digits first and 1 letter optional
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
//Used for class rooms | |
//Only uses this format: 1 or 2 digits first and 1 letter optional | |
//input examples: "2k", "20k", "1", "10" | |
//output examples:"02k","20k", "01", "10" | |
function addZeroToFront(nr) { | |
var val = nr; | |
var numbers = Number(val.replace(/[a-zA-Z]/g, '')); | |
var letter = val.replace(/[0-9]/g, ''); | |
if (val !== "") { | |
var letter = val.replace(/[0-9]/g, ''); | |
var numbers = Number(val.replace(/[a-zA-Z]/g, '')); | |
if (numbers.toString().length === 1 && val !== 0) { | |
return "0" + numbers + letter; | |
} | |
} | |
return val | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment