Find Number Plate Based on Registration Number in JavaScript

AmitDiwan
Updated on 17-Apr-2021 11:14:19

665 Views

ProblemThe 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: ... Read More

Convert String to NATO Phonetic Alphabets in JavaScript

AmitDiwan
Updated on 17-Apr-2021 11:07:19

853 Views

ProblemWe are required to write a JavaScript function that takes in a string and converts it into NATO phonetic alphabet.The 26 code words are as follows: Alfa, Bravo, Charlie, Delta, Echo, Foxtrot, Golf, Hotel, India, Juliett, Kilo, Lima, Mike, November, Oscar, Papa, Quebec, Romeo, Sierra, Tango, Uniform, Victor, Whiskey, X-ray, Yankee, Zulu.ExampleFollowing is the code − Live Democonst str = 'this is simple string'; const convertToNato = (str = '') => {    let nato = {       a: 'Alfa',       b: 'Bravo',       c: 'Charlie',       d: 'Delta',       e: ... Read More

Convert Miles Per Gallon to Kilometer Per Liter in JavaScript

AmitDiwan
Updated on 17-Apr-2021 11:03:35

594 Views

ProblemWe are required to write a JavaScript function that takes in a number in miles/gallon and return its equivalent km/litre.ExampleFollowing is the code − Live Democonst num = 25; const converter = (mpg) => {    let LITRES_PER_GALLON = 4.54609188;    let KILOMETERS_PER_MILE = 1.609344;    const ratio = KILOMETERS_PER_MILE / LITRES_PER_GALLON;    return Math.round(100 * mpg * ratio) / 100; }; console.log(converter(num));OutputFollowing is the console output −8.85

Finding Whether a Number is Triangular in JavaScript

AmitDiwan
Updated on 17-Apr-2021 11:02:23

431 Views

Triangular NumberTriangular number is the number of points that can fill an equilateral triangle.For instance − 9 is a triangular number which makes an equilateral triangle with each side of 4 units.ProblemWe are required to write a JavaScript function that takes in a number and returns true if its a triangular number, false otherwise.ExampleFollowing is the code − Live Democonst num = 9; const isTriangular = (num = 1) => {    let i = 4;    if(num === 1){       return true;    };    if(num === 3){       return true;    };    while(((3 * 1) - 3)

Finding Quarter Based on Month Index in JavaScript

AmitDiwan
Updated on 17-Apr-2021 11:00:13

647 Views

ProblemWe are required to write a JavaScript function that takes in the 1-based month index and return the quarter, which the month falls in.ExampleFollowing is the code − Live Democonst month = 7; const findQuarter = (month = 1) => {    if (month

Convert Number to Corresponding String in JavaScript

AmitDiwan
Updated on 17-Apr-2021 10:53:56

368 Views

ProblemWe are required to write a JavaScript function that takes in a number n and converts it to the corresponding string without using the inbuilt functions String() or toString() or using string concatenation.ExampleFollowing is the code − Live Democonst num = 235456; const convertToString = (num) => {    let res = '';    while(num){       res = (num % 10) + res;       num = Math.floor(num / 10);    };    return res; }; console.log(convertToString(num));OutputFollowing is the console output −235456

Check for Doubleton Number in JavaScript

AmitDiwan
Updated on 17-Apr-2021 10:52:04

315 Views

Doubleton NumberWe will call a natural number a "doubleton number" if it contains exactly two distinct digits. For example, 23, 35, 100, 12121 are doubleton numbers, and 123 and 9980 are not.ProblemWe are required to write a JavaScript function that takes in a number and return true if it is a doubleton number, false otherwise.ExampleFollowing is the code − Live Democonst num = 121212; const isDoubleTon = (num = 1) => {    const str = String(num);    const map = {};    for(let i = 0; i < str.length; i++){       const el = str[i];       ... Read More

Convert to Hex and Sum Numeral Part in JavaScript

AmitDiwan
Updated on 17-Apr-2021 10:49:30

300 Views

ProblemWe are required to write a JavaScript function that takes in a string. Our function should convert every character of the string to the hex value of its ascii code, then the result should be the sum of the numbers in the hex strings ignoring the letters present in hex.ExampleFollowing is the code − Live Democonst str = "Hello, World!"; const toHexAndSum = (str = '') => {    return str    .split('')    .map(c=>c.charCodeAt())    .map(n=>n.toString(16))    .join('')    .split('')    .filter(c=>'123456789'.includes(c))    .map(d=>parseInt(d))    .reduce((a, b)=>a+b, 0) }; console.log(toHexAndSum(str));OutputFollowing is the console output −91Read More

Finding the Nth Element of the Lucas Number Sequence in JavaScript

AmitDiwan
Updated on 17-Apr-2021 10:32:56

288 Views

Lucas NumbersLucas numbers are numbers in a sequence defined like this −L(0) = 2 L(1) = 1 L(n) = L(n-1) + L(n-2)ProblemWe are required to write a JavaScript function that takes in a number n and return the nth lucas number.ExampleFollowing is the code − Live Democonst num = 21; const lucas = (num = 1) => {    if (num === 0)       return 2;    if (num === 1)       return 1;    return lucas(num - 1) +       lucas(num - 2); }; console.log(lucas(num));OutputFollowing is the console output −24476

Permutation of a Given String Using Inbuilt Function in Python

Hafeezul Kareem
Updated on 16-Apr-2021 19:44:10

3K+ Views

In this tutorial, we are going to find the permutation of a string using the inbuilt function of Python called permutations. The method permutations is present in the itertools module.Procedure To Find The Permutation Of A StringImport the itertools module.Initialize the string.Use the itertools.permutations method to find the permutation of the string.In the third step, the method returns an object and convert it into a list.List contains a permutation of string as tuples.ExampleLet's see the program.## importing the module import itertools ## initializing a string string = "XYZ" ## itertools.permutations method permutaion_list = list(itertools.permutations(string)) ## printing the obj in list print("-----------Permutations Of String ... Read More

Advertisements