AmitDiwan has Published 10744 Articles

How to split last n digits of each value in the array with JavaScript?

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 13:39:47

312 Views

We have an array of literals like this −const arr = ["", 20191219, 20191220, 20191221, 20191222, 20191223, 20191224, 20191225];We are required to write a JavaScript function that takes in this array and a number n and if the corresponding element contains more than or equal to n characters, then the ... Read More

JavaScript Return an array that contains all the strings appearing in all the subarrays

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 13:37:24

295 Views

We have an array of arrays like this −const arr = [    ['foo', 'bar', 'hey', 'oi'],    ['foo', 'bar', 'hey'],    ['foo', 'bar', 'anything'],    ['bar', 'anything'] ]We are required to write a JavaScript function that takes in such array and returns an array that contains all the strings ... Read More

Reverse numbers in function without using reverse() method in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 13:32:48

1K+ Views

We are required to write a JavaScript function that takes in a number and returns its reversed number with converting it to an array or string.Let's write the code for this function −Exampleconst num = 234567; const reverseNumber = (num, res = 0) => {    if(num){       ... Read More

Maximum products of two integers in linear time in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 13:29:48

138 Views

We are required to write a JavaScript function that takes in an array of Numbers with positive as well as negative numbers and returns the maximum products of two numbers in one traversal.Let's write the code for this function −Exampleconst arr = [-1, -3, -4, 2, 0, -5]; const arr2 ... Read More

Separate odd and even in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 13:02:05

742 Views

We are required to write a JavaScript function that takes in an array of numbers and returns an array with all even numbers appearing on the left side of any odd number and all the odd numbers appearing on the right side of any even number.Therefore, let's write the code ... Read More

Wildcard matching of string JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 12:51:07

2K+ Views

We are required to write a JavaScript function that accepts two strings and a number n. The function matches the two strings i.e., it checks if the two strings contains the same characters. The function should return true if both the strings contain the same character irrespective of their order ... Read More

Object difference in JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 12:48:57

144 Views

We are required to write a JavaScript function that takes in two objects (possibly nested) and returns a new object with key value pair for the keys that were present in the first object but not in the secondLet's write the code for this function −Exampleconst obj1 = {   ... Read More

Rearrange string so that same character become n distance apart JavaScript

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 12:46:33

265 Views

We are required to write a JavaScript function that takes in a string with repetitive characters and returns a new string in which all the same characters are exactly n characters away from each other. And the number should be smaller than the length of the array.For example −If the ... Read More

JavaScript R- eturn Array Item(s) With Largest Score

AmitDiwan

AmitDiwan

Updated on 31-Aug-2020 12:36:17

148 Views

We have an array of arrays that contains the marks scored by some students in some subjects −const arr = [    ['Math', 'John', 100],    ['Math', 'Jake', 89],    ['Math', 'Amy', 93],    ['Science', 'Jake', 89],    ['Science', 'John', 89],    ['Science', 'Amy', 83],    ['English', 'John', 82],   ... Read More

Split string into equal parts JavaScript

AmitDiwan

AmitDiwan

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

934 Views

We are required to write a JavaScript function that takes in a string and a number n as two arguments (the number should be such that it exactly divides the length of string). And we have to return an array of n strings of equal length.For example −If the string ... Read More

Advertisements