AmitDiwan has Published 10744 Articles

Splitting number to contain continuous odd or even number using JavaScript

AmitDiwan

AmitDiwan

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

261 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

790 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

137 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

240 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

553 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

Finding the immediate next character to a letter in string using JavaScript

AmitDiwan

AmitDiwan

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

1K+ Views

ProblemWe are required to write a JavaScript function that takes in a string of characters, str, and a single character, char.Our function should construct a new string that contains the immediate next character present in str after each instance of char (if any).ExampleFollowing is the code − Live Democonst str = ... Read More

Removing least number of elements to convert array into increasing sequence using JavaScript

AmitDiwan

AmitDiwan

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

161 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers. Our function should try and remove the least number of elements from the array so that the array becomes an increasing sequence.ExampleFollowing is the code − Live Democonst arr = [1, 100, 2, 3, 100, 4, ... Read More

JavaScript function that lives on the prototype object of the Array class

AmitDiwan

AmitDiwan

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

100 Views

ProblemWe are required to write a JavaScript function that lives on the prototype object of the Array class. This function should take in a callback function and this function should return that very first element for which the callback function yields true.We should feed the current element and the current ... Read More

Constructing a string of alternating 1s and 0s of desired length using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:46:42

572 Views

ProblemWe are required to write a JavaScript function that takes in a number n. Starting with ‘1’ our function should construct a string of length n that contains ‘1’ and ‘0’ alternatingly.ExampleFollowing is the code − Live Democonst num = 12; const buildString = (num = 1) => {    let ... Read More

Reversing the bits of a decimal number and returning new decimal number in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:35:00

272 Views

ProblemWe are required to write a JavaScript function that takes in a decimal number, converts it into binary and reverses its 1 bit to 0 and 0 to 1 and returns the decimal equivalent of new binary thus formed.ExampleFollowing is the code − Live Democonst num = 45657; const reverseBitsAndConvert = ... Read More

Advertisements