AmitDiwan has Published 10744 Articles

Sum all perfect cube values upto n using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:30:04

281 Views

ProblemWe are required to write a JavaScript function that takes in a number n and returns the sum of all perfect cube numbers smaller than or equal to n.ExampleFollowing is the code − Live Democonst num = 23546; const sumPerfectCubes = (num = 1) => {    let i = 1;    let sum = 0;    while(i * i * i

Finding the sum of all numbers in the nth row of an increasing triangle using JavaScript

AmitDiwan

AmitDiwan

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

248 Views

Increasing TriangleFor the purpose of this problem, suppose an increasing triangle to be like this −   1   2 3  4 5 6 7 8 9 10ProblemWe are required to write a JavaScript function that takes in a number n and returns the sum of numbers present in the nth ... Read More

Sum of individual even and odd digits in a string number using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:24:22

587 Views

ProblemWe are required to write a JavaScript function that takes in string containing digits and our function should return true if the sum of even digits is greater than that of odd digits, false otherwise.ExampleFollowing is the code − Live Democonst num = '645457345'; const isEvenGreater = (str = '') => ... Read More

Finding number of open water taps after n chances using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:21:58

104 Views

ProblemSuppose a school organises this game on their Annual Day celebration −There are ”n” water taps and “n” students are chosen at random. The instructor asks the first student to go to every tap and open it. Then he has the second student go to every second tap and close ... Read More

Sorting an array that contains the value of some weights using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:21:39

369 Views

ProblemWe are required to write a JavaScript function that takes in an array of string that contains weights with three units: grams (G), kilo-grams (KG) and tonnes (T). Our function should sort the array into order of weight from light to heavy.We are required to write a JavaScript function that ... Read More

Moving all vowels to the end of string using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:21:22

329 Views

ProblemWe are required to write a JavaScript function that takes in a string. Our function should construct a new string in which all the consonants should hold their relative position and all the vowels should be pushed to the end of string.ExampleFollowing is the code − Live Democonst str = 'sample ... Read More

Sorting according to number of 1s in binary representation using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:21:06

179 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers. Our function should sort the numbers according to decreasing number of 1s present in the binary representation of those numbers and return the new array.ExampleFollowing is the code − Live Democonst arr = [5, 78, 11, ... Read More

Unique pairs in array that forms palindrome words in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:18:04

147 Views

ProblemWe are required to write a JavaScript function that takes in an array of unique words.Our function should return an array of all such index pairs, the words at which, when combined yield a palindrome word.ExampleFollowing is the code − Live Democonst arr = ["abcd", "dcba", "lls", "s", "sssll"]; const findPairs ... Read More

Converting numbers into corresponding alphabets and characters using JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:16:09

516 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers in string format. Our function must return a string. The numbers correspond to the letters of the alphabet in reverse order: a=26, z=1 etc.We should also account for '!', '?' and ' ' that are ... Read More

Turn each character into its ASCII character code and join them together to create a number in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Apr-2021 11:15:53

321 Views

ProblemWe are required to write a JavaScript function that takes in a string. Our function should turn each character into its ASCII character code and join them together to create a number. Then we should replace all instances of 7 from this number to 1 to construct another number. Finally, ... Read More

Advertisements