AmitDiwan has Published 10744 Articles

Finding nearest Gapful number in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Aug-2020 06:46:32

273 Views

A number is a gapful number when −It has at least three digits, andIt is exactly divisible by the number formed by putting its first and last digits togetherFor example −The number 1053 is a gapful number because it has 4 digits and it is exactly divisible by 13. Similarly, ... Read More

How to remove “,” from a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Aug-2020 06:45:08

170 Views

We are given a main string and a substring, our job is to create a function shedString() that takes in these two arguments and returns a version of the main string which is free of the substring.For example −shedString('12/23/2020', '/');should return a string −'12232020'Let’s now write the code for this ... Read More

Create a polyfill to replace nth occurrence of a string JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Aug-2020 06:43:56

502 Views

Let’s say, we have created a polyfill function removeStr() that takes in three arguments, namely −subStr → the occurrence of which String is to be removednum → it’s a Number (num)th occurrence of subStr is to be removed from stringThe function should return the new if the removal of the ... Read More

Finding out the Harshad number JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Aug-2020 06:42:30

574 Views

Harshad numbers are those numbers which are exactly divisible by the sum of their digits. Like the number 126, it is completely divisible by 1+2+6 = 9.All single digit numbers are harshad numbers.Harshad numbers often exist in consecutive clusters like [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ... Read More

How to create a random number between a range JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Aug-2020 06:39:28

248 Views

Our job is to create a function, say createRandom, that takes in two argument and returns a pseudorandom number between the range (max exclusive).The code for the function will be −Exampleconst min = 3; const max = 9; const createRandom = (min, max) => {    const diff = max ... Read More

How to exclude certain values from randomly generated array JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Aug-2020 06:38:09

1K+ Views

We have to create a function that takes in 2 arguments: an integer and an array of integers. First argument denotes the length of array we have to return and the second argument contains the elements that should not be present in our return array. Actually, we need an array ... Read More

JavaScript array.includes inside nested array returning false where as searched name is in array

AmitDiwan

AmitDiwan

Updated on 18-Aug-2020 07:43:39

1K+ Views

It is a well-known dilemma that when we use includes() inside nested arrays i.e., multidimensional array, it does not work, there exists a Array.prototype.flat() function which flats the array and then searches through but it’s browser support is not very good yet.So our job is to create a includesMultiDimension() function ... Read More

When summing values from 2 arrays how can I cap the value in the new JavaScript array?

AmitDiwan

AmitDiwan

Updated on 18-Aug-2020 07:42:25

105 Views

Suppose, we have two arrays both containing three elements each, the corresponding values of red, green, blue color in integer.Our job is to add the corresponding value to form an array for new rgb color and also making sure if any value adds up to more than 255, we that ... Read More

Title Case A Sentence JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Aug-2020 07:41:22

290 Views

Let’s say we are required to write a function that accepts a string and capitalizes the first letter of every word in that string and changes the case of all the remaining letters to lowercase.For example, if the input string is −hello world coding is very interestingThe output should be ... Read More

How to find the one integer that appears an odd number of times in a JavaScript array?

AmitDiwan

AmitDiwan

Updated on 18-Aug-2020 07:40:26

184 Views

We are given an array of integers and told that all the elements appear for an even number of times except a single element. Our job is to find that element in single iteration.Let this be the sample array −[1, 4, 3, 4, 2, 3, 2, 7, 8, 8, 9, ... Read More

Advertisements