AmitDiwan has Published 8358 Articles

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

231 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

452 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

Mean of an array rounded down to nearest integer in JavaScript

AmitDiwan

AmitDiwan

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

399 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

486 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

Splitting number to contain continuous odd or even number using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 22:03:33

299 Views

ProblemWe are required to write a JavaScript function that takes in a number n(n>0). Our function should return an array that contains the continuous parts of odd or even digits. It means that we should split the number at positions when we encounter different numbers (odd for even, even for ... Read More

Constructing a sentence based on array of words and punctuations using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 22:03:19

857 Views

ProblemWe are required to write a JavaScript function that takes in an array of words and punctuations. Our function should join array elements to construct a sentence based on the following rules −there must always be a space between words;there must not be a space between a comma and word ... Read More

Returning array values that are not odd in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 22:02:59

174 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers.Our function should construct and return a new array that contains all the numbers of the input array that are not odd.ExampleFollowing is the code − Live Democonst arr = [5, 32, 67, 23, 55, 44, 23, ... Read More

Finding nth element of the Padovan sequence using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:48:27

277 Views

Padovan SequenceThe Padovan sequence is the sequence of integers P(n) defined by the initial values −P(0) = P(1) = P(2) = 1and the recurrence relation, P(n) = P(n-2) + P(n-3)The first few values of P(n) are1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, ... Read More

Finding all possible prime pairs that sum upto input number using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:47:55

586 Views

ProblemWe are required to write a JavaScript function that takes in a number n. Our function should return an array of all such number pairs that when summed are n and both of them are prime.ExampleFollowing is the code − Live Democonst num = 26; const isPrime = (n) => { ... Read More

Advertisements