AmitDiwan has Published 10744 Articles

Swapping string case using a binary number in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:21:37

202 Views

ProblemWe are required to write a JavaScript function that takes in a string str and a number n. Our function should change the given string str using n.Each bit in n will specify whether or not to swap the case for each alphabetic character in s −If the bit is ... Read More

Building a lexicographically increasing sequence of first n natural numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:19:36

114 Views

ProblemWe are required to write a JavaScript function that takes in a number n and return an array containing first n natural number.The only condition is that the numbers should be sorted lexicographically which means all the numbers starting with 1 should come before any starting with 2 or 3 ... Read More

Reversing words present in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:17:40

389 Views

ProblemWe are required to write a JavaScript function that takes in a string that represents a sentence.Our function should reverse the order of words present in the string and return the new string.It means that the last word should become the first, second last should be the second and so ... Read More

Finding sum of all numbers within a range in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:15:11

735 Views

ProblemWe are required to write a JavaScript function that takes in an array that specifies a range.Our function should find and return the sum of all the natural numbers falling in the range including the range numbers.ExampleFollowing is the code − Live Democonst range = [4, 67]; const findSum = ([l, ... Read More

Finding number plate based on registration number in JavaScript

AmitDiwan

AmitDiwan

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

636 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 ... Read More

Converting a string to NATO phonetic alphabets in JavaScript

AmitDiwan

AmitDiwan

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

802 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, ... Read More

Converting miles per gallon to kilometer per liter in JavaScript

AmitDiwan

AmitDiwan

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

572 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 / ... Read More

Finding whether a number is triangular number in JavaScript

AmitDiwan

AmitDiwan

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

396 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 ... Read More

Finding quarter based on month index in JavaScript

AmitDiwan

AmitDiwan

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

620 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

Converting number of corresponding string without using library function in JavaScript

AmitDiwan

AmitDiwan

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

350 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 ... Read More

Advertisements