AmitDiwan has Published 10744 Articles

Validating brackets in a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:30:02

964 Views

We are required to write a JavaScript function that takes in a string that might contain some opening and closing brackets. The function should whether for all the opening brackets there exists a closing bracket or not. If the brackets are rightly matched, the function should return true, false otherwise.For ... Read More

Min window substring in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:27:53

2K+ Views

We are required to write a JavaScript function that takes in two strings let's call them str1 and str2.The size of str1 is guaranteed to be greater than that of str2. We are required to find the smallest substring in str1 that contains all the characters contained in str2.For example ... Read More

Uncamelising a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:23:54

208 Views

We are required to write a JavaScript function that takes in a string as the first argument and a separator character as the second argument.The first string is guaranteed to be a camelCased string. The function should convert the case of the string by separating the words by the separator ... Read More

Swapcase function in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:22:48

559 Views

We are required to write a JavaScript function that takes in a string as the only argument.The string might contain both uppercase and lowercase alphabets.The function should construct a new string based on the input string in which all the uppercase letters are converted to lowercase and all the lowercase ... Read More

Masking email to hide it in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:21:51

3K+ Views

It is a common practice that when websites display anyone's private email address they often mask it in order to maintain privacy.Therefore for example −If someone's email address is −const email = 'ramkumar@example.com';Then it is displayed like this −const masked = 'r...r@example.com';We are required to write a JavaScript function that ... Read More

Finding all possible ways of integer partitioning in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:20:28

746 Views

The partition of a positive integer n is a way of writing n as a sum of positive integers. Two sums that differ only in the order of their summands are considered the same partition.For example, 4 can be partitioned in five distinct ways −4 3 + 1 2 + ... Read More

Finding square root of a number without using Math.sqrt() in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:19:00

807 Views

We are required to write a JavaScript function that takes in a positive integer as the only argument. The function should find and return the square root of the number provided as the input.ExampleFollowing is the code −const squareRoot = (num, precision = 0) => {    if (num ... Read More

Finding the common streak in two arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:17:27

235 Views

We are required to write a JavaScript function that takes in two arrays of literals, let’s call them arr1 and arr2.The function should find the longest common streak of literals in the arrays. The function should finally return an array of those literals.For example −If the input arrays are −const ... Read More

Maximum contiguous sum of subarray in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:15:43

290 Views

We are required to write a JavaScript function that takes in an array of array of positive and negative integers. Since the array also contains negative elements, the sum of contiguous elements can possibly be negative or positive.Our function should pick an array of contiguous elements from the array that ... Read More

Finding the longest common consecutive substring between two strings in JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:14:23

1K+ Views

We are required to write a JavaScript function that takes in two strings. Let’s call them str1 and str2. The function should then find out the longest consecutive string that is common to both the input strings and return that common string.For example −If the input strings are −const str1 ... Read More

Advertisements