AmitDiwan has Published 10744 Articles

Writing a custom URL shortener function in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 07:03:07

2K+ Views

ProblemWe are required to write two JavaScript functions −First function should take in a long url and return a short url that corresponds to it.The second function should take in the short url and redirect to the original url.ExampleFollowing is the code − Live Democonst url = 'https://www.google.com/search?client=firefox-b-d&q=google+search'; const obj = ... Read More

Generating the sequence of first n look and say numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 06:59:29

413 Views

ProblemIn mathematics, the look-and-say sequence is the sequence of integers beginning as follows −1, 11, 21, 1211, 111221, 312211, …To generate a member of the sequence from the previous member, we read off the digits of the previous member, counting the number of digits in groups of the same digit.For ... Read More

Rectifying the time string in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 06:56:18

100 Views

ProblemWe are required to write a JavaScript function that takes in a time string in “HH:MM:SS” format.But there was a problem in addition, so many of the time strings are broken which means the MM part may exceed 60, and SS part may as well exceed 60.Our function should make ... Read More

Counting the number of IP addresses present between two IP addresses in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 06:41:40

1K+ Views

ProblemWe are required to write a JavaScript function that takes in two IPv4 addresses, and returns the number of addresses between them (including the first one, excluding the last one).This can be done by converting them to decimal and finding their absolute difference.ExampleFollowing is the code − Live Democonst ip1 = ... Read More

Converting an unsigned 32 bit decimal to corresponding ipv4 address in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 06:37:34

1K+ Views

ProblemConsider the following ipv4 address −128.32.10.1If we convert it to binary, the equivalent will be −10000000.00100000.00001010.00000001And further if we convert this binary to unsigned 32 bit decimal, the decimal will be −2149583361Hence, we can say that the ipv4 equivalent of 2149583361 is 128.32.10.1We are required to write a JavaScript function ... Read More

Converting decimal to binary or hex based on a condition in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 06:34:14

200 Views

ProblemWe are required to write a JavaScript function that takes in a number n. Our function should convert the number to binary or hex based on −If a number is even, convert it to binary.If a number is odd, convert it to hex.ExampleFollowing is the code − Live Democonst num = ... Read More

Finding the k-prime numbers with a specific distance in a range in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 06:30:49

408 Views

K-Prime NumbersA natural number is called k-prime if it has exactly k prime factors, counted with multiplicity.Which means even though the only prime factor of 4 is 2 it will be a 2-prime number because −4 = 2 * 2 and both 2s will be counted separately taking the count ... Read More

Mapping array of numbers to an object with corresponding char codes in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 06:24:47

628 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers. For each number in the array, we need to create an object. The object key will be the number, as a string. And the value will be the corresponding character code, as a string.We should ... Read More

Mean of an array rounded down to nearest integer in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 06:22:24

361 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers. Our function is supposed to return the average of the given array rounded down to its nearest integer.ExampleFollowing is the code − Live Democonst arr = [45, 23, 67, 68, 12, 56, 99]; const roundedMean = ... Read More

Finding the largest 5 digit number within the input number using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 22:04:34

446 Views

ProblemWe are required to write a JavaScript function that takes in a string number of at least five digits. Our function should return the greatest sequence of five consecutive digits found within the number given.ExampleFollowing is the code − Live Democonst num = '123546544'; const findGreatestFiveDigit = (num = '') => ... Read More

Advertisements