AmitDiwan has Published 10740 Articles

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

238 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

575 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

792 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

837 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

262 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

317 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

Radix sort - JavaScript

AmitDiwan

AmitDiwan

Updated on 11-Dec-2020 09:12:41

429 Views

Radix Sort Radix sort is a sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value.We are required to write a JavaScript function that takes in an array of literals as the only argument. The function should sort ... Read More

Advertisements