AmitDiwan has Published 10740 Articles

Separating data type from array into groups in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:42:09

614 Views

ProblemWe are required to write a JavaScript function that takes in an array of mixed data types. Our function should return an object that contains data type names as key and their value as array of elements of that specific data type present in the array.ExampleFollowing is the code − Live ... Read More

Mathematics summation function in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:40:30

2K+ Views

ProblemWe are required to write a JavaScript function that takes in a number n. Our function should return the sum of all the natural numbers from 1 to n including both 1 and nExampleFollowing is the code − Live Democonst num = 34; const summation = (num = 1) => {    let res = 0;    for(let i = 1; i

Creating all possible unique permutations of a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:39:18

1K+ Views

ProblemWe are required to write a JavaScript function that takes in a string str. Our function should create all permutations of the input string and remove duplicates, if present. This means, we have to shuffle all letters from the input in all possible orders.ExampleFollowing is the code − Live Democonst str ... Read More

Returning number with increasing digits. in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:37:15

192 Views

ProblemWe are required to write a JavaScript function that takes in a number n. Our function should return it with its digits in descending order. Essentially, we should rearrange the digits to create the highest possible number.ExampleFollowing is the code − Live Democonst num = 5423267; const arrangeInDescending = (num = ... Read More

Currified function that multiples array elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:35:29

238 Views

ProblemWe are required to write a JavaScript function that takes in an array and returns another function which in turn takes in a number which returns a new array which is the product of corresponding elements of the input array to the first function and the number provided to the ... Read More

Returning the expanded form of a number in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:33:22

393 Views

ProblemWe are required to write a JavaScript function that takes in a number and returns a string of the expanded form of the number, indicating the place value of each number.ExampleFollowing is the code − Live Democonst num = 56577; const expandedForm = (num = 0) => {    const str ... Read More

Building an array of specific size with consecutive element sum being perfect square in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:29:55

170 Views

We are required to write a JavaScript function that takes in a number n. Our function should return an array of integers 1..n arranged in a way, such that the sum of each 2 consecutive numbers is a square.ExampleThe code for this will be − Live Democonst n = 15; const ... Read More

Accumulating some value over using a callback function and initial value in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:25:53

239 Views

ProblemWe are required to write a JavaScript function that takes in an array a callback function and an initial value.The function should accumulate a value over the iteration of array and finally return the value just like the Array.prototype.reduce() does.ExampleFollowing is the code − Live Democonst arr = [1, 2, 3, ... Read More

Finding nth day of the year in leap and non-leap years in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:24:23

341 Views

ProblemWe are required to write a JavaScript function that takes in a number as the first argument and boolean as the second argument.The boolean specifies a leap year (if it’s true). Based on this information our function should return the date that would fall on the nth day of the ... Read More

Swapping string case using a binary number in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 11:21:37

221 Views

ProblemWe are required to write a JavaScript function that takes in a string str and a number n. Our function should change the given string str using n.Each bit in n will specify whether or not to swap the case for each alphabetic character in s −If the bit is ... Read More

Advertisements