AmitDiwan has Published 10744 Articles

Swapping adjacent words of a String in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 07:56:39

491 Views

We are required to write a JavaScript function that takes in a string and swaps the adjacent words of that string with one another until the end of that string.ExampleThe code for this will be −const str = "This is a sample string only"; const replaceWords = str => { ... Read More

Finding two golden numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 07:54:43

147 Views

We are required to write a JavaScript function that takes in two numbers, say m and n and returns two numbers whose sum is n and product is m. If there exist no such numbers than our function should return false.ExampleThe code for this will be −const goldenNumbers = (sum, ... Read More

Delete every one of the two strings that start with the same letter in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 07:53:32

137 Views

We are required to write a JavaScript function that takes in an array of strings and deletes every one of the two strings that start with the same letter.For example, If the actual array is −const arr = ['Apple', 'Jack' , 'Army', 'Car', 'Jason'];Then we have to delete and keep ... Read More

Omitting false values while constructing string in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 07:51:58

91 Views

We have an array that contains some string values as well as some false values.We are required to write a JavaScript function that takes in this array and returns a string constructed by joining values of the array and omitting false values.ExampleThe code for this will be −const arr = ... Read More

Negative number digit sum in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 07:50:34

564 Views

We are required to write a JavaScript function that takes in a negative integer and returns the sum of its digits.For example: If the number is −-5456OutputThen the output should be −5+4+5+6 10ExampleThe code for this will be −const num = -5456; const sumNum = num => {    return ... Read More

Sum all duplicate values in array in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 07:48:31

2K+ Views

We are required to write a JavaScript function that takes in an array of numbers with duplicate entries and sums all the duplicate entries to one index.ExampleThe code for this will be −const input = [1, 3, 1, 3, 5, 7, 5, 3, 4]; const sumDuplicate = arr => { ... Read More

Difference of digits at alternate indices in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 07:45:31

102 Views

We are required to write a JavaScript function that takes in a number and returns the difference of the sums of the digits at even place and the digits odd place.ExampleThe code for this will be −const num = 123456; const alternateDifference = (num, res = 0, ind = 0) ... Read More

Finding clusters of consecutive negative integers in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 07:42:41

206 Views

We have an array of numbers like this −const arr = [-1, -2, -1, 0, -1, -2, -1, -2, -1, 0, 1, 0];We are required to write a JavaScript function that counts the consecutive groups of negative numbers in the array.ExampleThe code for this will be −const arr = [-1, ... Read More

Calculating factorial by recursion in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 07:41:11

199 Views

We are required to write a JavaScript function that computes the Factorial of a number n by making use of recursive approach.ExampleThe code for this will be −const num = 9; const recursiceFactorial = (num, res = 1) => {    if(num){       return recursiceFactorial(num-1, res * num); ... Read More

Checking for coprime numbers in JavaScript

AmitDiwan

AmitDiwan

Updated on 14-Oct-2020 07:38:56

877 Views

Two numbers are said to be co-primes if there exists no common prime factor amongst them (1 is not a prime number).We are required to write a function that takes in two numbers and returns true if they are coprimes otherwise returns false.ExampleThe code for this will be −const areCoprimes ... Read More

Advertisements