
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Finding number plate based on registration number in JavaScript
Problem
The car registering system of a city N assigns two types of numbers −
The Customer ID − a natural number between 0 and 17558423 inclusively, which is assigned to the car buyers in the following order: the first customer receives ID 0, the second customer receives ID 1, the third customer receives ID 2, and so on;
Number Plate − assigned to the car and contains the series ( three Latin lowercase letters from a to z) and the serial number (three digits from 0 to 9).
Example − aaa001. Each Number Plate is related to the given Customer ID. For example: Number Plate aaa001 is related to Customer ID 0; Number Plate aaa002 is related to Customer ID 1, and so on.
We are required to write a JavaScript function that takes in the customerID and calculates the Number Plate corresponding to this ID and returns it as a string.
Example
Following is the code −
const id = 545664; const findNumberPlate = (id = 0) => { const letters = 'abcdefghijklmnopqrstuvwxyz'; let num = String(id % 999 + 1); if(num.length !== 3); while(num.length !== 3){ num = '0' + num; }; const l = Math.floor(id / 999); return letters[l % 26] + letters[(Math.floor(l / 26)) % 26] + letters[(Math.floor(l / (26 * 26))) % 26] + num; }; console.log(findNumberPlate(id));
Output
Following is the console output −
ava211
- Related Articles
- Finding life path number based on a date of birth in JavaScript
- Finding quarter based on month index in JavaScript
- Finding Gapful number in JavaScript
- Finding astrological signs based on birthdates using JavaScript
- Finding whether a number is triangular number in JavaScript
- Finding persistence of number in JavaScript
- Finding nearest Gapful number in JavaScript
- Finding smallest number using recursion in JavaScript
- Finding unlike number in an array - JavaScript
- Finding closed loops in a number - JavaScript
- Finding product of Number digits in JavaScript
- Finding the smallest fitting number in JavaScript
- Finding the nth prime number in JavaScript
- Finding a number, when multiplied with input number yields input number in JavaScript
- JavaScript Recursion finding the smallest number?
