AmitDiwan has Published 10744 Articles

Reverse all the words of sentence JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 06:56:12

4K+ Views

We are required to write a JavaScript function that takes in a string and returns a new string which has all the words reversed from the original string.For example −If the original string is −"Hello World how is it outside"Then the output should be −"olleH dlroW woH si ti edistuo"Now, ... Read More

Remove all characters of first string from second JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 06:53:32

373 Views

Let’s say, we have two strings that contains characters in no specific order. We are required to write a function that takes in these two strings and returns a modified version of the second string in which all the characters that were present in the first string are omitted.Following are ... Read More

Smallest positive value that cannot be represented as sum of subarray JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 06:52:36

144 Views

We have a sorted array of positive integers like this −const arr = [1, 3, 6, 10, 11, 15];We are required to write a function, say findSmallest() that takes in one such array and returns the smallest positive integer that cannot be represented as the sum of some subarray of ... Read More

Return Top two elements from array JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 06:51:08

327 Views

We have an array of numbers in JavaScript that contains numbers in an unsorted order. Our job is to write a function that takes in this array of numbers and returns an array of two elements, the top two elements of the array (greatest two elements of the array).We have ... Read More

Finding first non-repeating character JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 06:49:38

766 Views

We have an array of Numbers/String literals where most of the entries are repeated. Our job is to write a function that takes in this array and returns the index of first such element which does not make consecutive appearances.If there are no such elements in the array, our function ... Read More

Find the difference of largest and the smallest number in an array without sorting it in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 06:45:54

352 Views

We have an array of Numbers that are arranged in pure random order. Our job is to write a function that takes in one such array of Numbers and returns the difference of greatest and smallest numbers present in it, but without sorting the array.Therefore, let's write the code for ... Read More

JavaScript array: Find all elements that appear more than n times

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 06:44:32

396 Views

We have an array of Number/String literals that contains some repeated entries. Our job is to write a function that takes in a positive integer Number n and returns a subarray of all the elements that makes appearance more than or equal to the number n specified by the only ... Read More

Searching objects by value in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 06:43:17

154 Views

Suppose we have an object like this −const obj = {    "name": "Vivek Sharma",    "occupation": "Software Engineer",    "age": 23,    "contacts": [{       "name": "Mukul Sharma",       "occupation": "Software Engineer",       "age": 31,    }, {       "name": "Jay ... Read More

Reverse index value sum of array in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 06:41:10

242 Views

Suppose we have an array of numbers like this −const arr = [3, 6, 7, 3, 1, 4, 4, 3, 6, 7];This array in the example contains 10 elements, so the index of last element happens to be 9. We are required to write a function that takes in one ... Read More

Solution to the clumsy factorial problem in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 06:40:11

353 Views

Normally, the factorial of a positive integer n is the product of all positive integers less than or equal to n. For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.We instead make a clumsy factorial: using ... Read More

Advertisements