AmitDiwan has Published 10744 Articles

Check for Subarray in the original array with 0 sum JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 12:28:03

439 Views

We are required to write a JavaScript function that takes in an array of Numbers with some positive and negative values. We are required to determine whether there exists a subarray in the original array whose net sum is 0 or not.Our function should return a boolean on this basis.ApproachThe ... Read More

Create a custom toLowerCase() function in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 12:25:49

437 Views

We are required to write a JavaScript String function that overwrite the default toLowerCase() and should have the same functionality as the default function.Let's write the code for this function −Exampleconst str = 'Some UpPerCAsE LeTTeRs!!!'; const toLowerCase = function(){    let str = '';    for(let i = 0; ... Read More

Segregate all 0s on right and 1s on left in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 12:24:26

223 Views

We have an array of Numbers that contains 0, 1 and some other numbers. We are required to write a JavaScript function that takes in this array and brings all 1s to the start and 0s to the endLet's write the code for this function −Exampleconst arr = [3, 2, ... Read More

Mersenne prime in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 12:22:44

295 Views

In Mathematics, a Mersenne prime is a number that can be written in the form M(n) = 2^n − 1 for some integer n and is actually a prime number.For example − The first four Mersenne primes are 3, 7, 31, and 127We are required to write a JavaScript function ... Read More

Return TRUE if the first string starts with a specific second string JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 12:21:12

206 Views

We are required to write a JavaScript function that takes in two strings and checks whether first string starts with second or notFor example −If the two strings are: “Disaster management report” “Disas” Then our function should return trueLet's write the code for this function −Exampleconst first = 'The game ... Read More

Leaders array JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 12:19:45

361 Views

An element in an array of Numbers is a leader if it is greater than all the elements on its right side. We are required to write a JavaScript function that takes in an array of Numbers and returns a subarray of all the elements that are fulfil the criteria ... Read More

JavaScript Determine the array having majority element and return TRUE if its in the same array

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 07:09:46

157 Views

We are required to write a JavaScript function that takes in an array of numbers with repetitive values and returns the number that appears for more than (n/2) number of times where n is the length of the array. If there is no such element in the array, our function ... Read More

Equality of two arrays JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 07:03:35

371 Views

We are required to write a JavaScript function that takes in two arrays of Numbers, say first and second and checks for their equality.Equality in our case will be determined by one of these two conditions −The arrays are equal if they contain the same elements irrespective of their order.If ... Read More

JavaScript Check whether string1 ends with strings2 or not

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 07:00:38

121 Views

We are required to write a JavaScript function that takes in two strings, say, string1 and string2 and determines whether the string1 ends with string2 or not.For example −"The game is on" Here, "on" should return trueWhile, "the game is off" Above, “of" should return falseLet's write the code for ... Read More

Check for Ugly number in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 06:59:27

1K+ Views

In the decimal number system, ugly numbers are those positive integers whose only prime factors are 2, 3 or 5.For example − Integers from 1 to 10 are all ugly numbers, 12 is an ugly number as well.Our job is to write a JavaScript function that takes in a Number ... Read More

Advertisements