AmitDiwan has Published 10744 Articles

Maximum absolute difference of the length of strings from two arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:33:33

275 Views

ProblemWe are required to write a JavaScript function that takes in two arrays, a1 and a2 of strings. Each string is composed with letters from a to z. Let x be any string in the first array and y be any string in the second array.Our function should find the ... Read More

Representing number as the power and product of primes in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:32:41

221 Views

ProblemWe are required to write a JavaScript function that takes in a positive integer. Our function should represent this number as the sum of some powers of prime numbers.Therefore, for the number n, our function should return a string like this −n = "(p1**n1)(p2**n2)...(pk**nk)"Where p1, p2, p3..pk are prime numbers ... Read More

Frequency of elements of one array that appear in another array using JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:31:56

529 Views

ProblemWe are required to write a JavaScript function that takes in two arrays of strings. Our function should return the number of times each string of the second array appears in the first array.ExampleFollowing is the code − Live Democonst arr1 = ['abc', 'abc', 'xyz', 'cde', 'uvw']; const arr2 = ['abc', ... Read More

Sorting string of words based on the number present in each word using JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:28:01

615 Views

ProblemWe are required to write a JavaScript function that takes in a string that represents a sentence. Our function should sort this sentence.Each word in the sentence string contains an integer. Our function should sort the string such that the word that contains the smallest integer is placed first and ... Read More

Returning the value of nth power of iota(i) using JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:27:07

128 Views

ProblemWe are required to write a JavaScript function that takes in a number. Our function should return the value of −(i)nHere, i = -11/2Therefore, i^2 = -1 i^3 = -i i^4 = 1 and so onExampleFollowing is the code − Live Democonst num = 657; const findNthPower = (num = 1) ... Read More

Finding and returning uncommon characters between two strings in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:26:27

1K+ Views

ProblemWe are required to write a JavaScript function that takes in two strings. Our function should return a new string of characters which is not common to both the strings.ExampleFollowing is the code − Live Democonst str1 = "xyab"; const str2 = "xzca"; const findUncommon = (str1 = '', str2 = ... Read More

Removing consecutive duplicates from strings in an array using JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:26:02

994 Views

ProblemWe are required to write a JavaScript function that takes in an array of strings. Our function should remove the duplicate characters that appear consecutively in the strings and return the new modified array of strings.ExampleFollowing is the code − Live Democonst arr = ["kelless", "keenness"]; const removeConsecutiveDuplicates = (arr = ... Read More

Reversing a string while maintaining the position of spaces in JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:25:01

790 Views

ProblemWe are required to write a JavaScript function that takes in a string that might contain some spaces.Our function should reverse the words present in the string internally without interchange the characters of two separate words or the spaces.ExampleFollowing is the code − Live Democonst str = 'this is normal string'; ... Read More

Counting prime numbers that reduce to 1 within a range using JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:22:43

170 Views

ProblemWe are required to write a JavaScript function that takes in a range array of two numbers. Our function should return the count of such prime numbers whose squared sum of digits eventually yields 1.For instance, 23 is a prime number and, 22 + 32 = 13 12 + 32 ... Read More

Swapping adjacent binary bits of a decimal to yield another decimal using JavaScript

AmitDiwan

AmitDiwan

Updated on 20-Apr-2021 09:21:40

172 Views

ProblemWe are required to write a JavaScript function that takes in a number.Our function should iterate through the binary equivalent of the number and swap its adjacent bits to construct a new binary. And then finally our function should return the decimal equivalent of the new binary.ExampleFollowing is the code ... Read More

Advertisements