Web Development Articles

Page 230 of 801

Expressive words problem case in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 266 Views

Sometimes people repeat letters to represent extra feeling, such as "hello" → "heeellooo", "hi" → "hiiii". In these strings like "heeellooo", we have groups of adjacent letters that are all the same: "h", "eee", "ll", "ooo". For some given string S, a query word is stretchy if it can be made to be equal to S by any number of applications of the following extension operation: choose a group consisting of characters c, and add some number of characters c to the group so that the size of the group is 3 or more. For example, starting with ...

Read More

Possible combinations and convert into alphabet algorithm in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 277 Views

In JavaScript, we can solve the alphabet decoding problem where each letter maps to a number (a=1, b=2, ..., z=26). Given an encoded message, we need to count how many different ways it can be decoded back into letters. For example, the message '111' can be decoded as 'aaa' (1-1-1), 'ka' (11-1), or 'ak' (1-11), giving us 3 possible combinations. Understanding the Problem The challenge is that some digit sequences can be interpreted in multiple ways: Single digits 1-9 can be decoded as letters a-i Two-digit combinations 10-26 can be decoded as letters j-z We ...

Read More

Program to make vowels in string uppercase and change letters to next letter in alphabet (i.e. z->a) in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 568 Views

We need to write a JavaScript function that takes a string and performs two transformations: convert vowels to uppercase and shift each letter to the next letter in the alphabet (with 'z' wrapping to 'a'). The function should construct a new string based on the input string where all vowels are uppercased and each alphabet character moves to the next letter in sequence. Problem Understanding For example, if the input string is: const str = 'newString'; The expected output should be: const output = 'oExSusIoh'; Here's how the transformation ...

Read More

How to store two arrays as a keyvalue pair in one object in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 782 Views

Suppose, we have two arrays of literals of same length like these − const arr1 = ['firstName', 'lastName', 'age', 'address', 'isEmployed']; const arr2 = ['Rahul', 'Sharma', 23, 'Tilak Nagar', false]; We are required to write a JavaScript function that takes in two such arrays. The function should construct an object mapping the elements of the second array to the corresponding elements of the first array. Method 1: Using Array.reduce() We will use the Array.prototype.reduce() method to iterate over the arrays, building the object. const arr1 = ['firstName', 'lastName', 'age', 'address', 'isEmployed']; ...

Read More

Finding the longest "uncommon" sequence in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 221 Views

We are required to write a JavaScript function that takes in an array of strings. The function should find the longest uncommon subsequence among the strings of the array. By longest uncommon subsequence we mean the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other strings. Our function should return the length of this longest uncommon subsequence. For example: If the input array is − const arr = ["aba", "cdc", "eae"]; Then the output should be 3. Understanding the Problem The key ...

Read More

Finding product of an array using recursion in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 685 Views

We are required to write a JavaScript function that takes in an array of numbers. Our function should do the following two things: Make use of a recursive approach. Calculate the product of all the elements in the array. And finally, it should return the product. For example, if the input array is: const arr = [1, 3, 6, 0.2, 2, 5]; Then the output should be: 36 How Recursion Works Recursion breaks down the problem into smaller subproblems. For ...

Read More

Find what numbers were pressed to get the word (opposite of phone number digit problem) in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 205 Views

The mapping of the numerals to alphabets in the old keypad type phones used to be like this: const mapping = { 1: [], 2: ['a', 'b', 'c'], 3: ['d', 'e', 'f'], 4: ['g', 'h', 'i'], 5: ['j', 'k', 'l'], 6: ['m', 'n', 'o'], 7: ['p', 'q', 'r', 's'], 8: ['t', 'u', 'v'], 9: ['w', 'x', 'y', 'z'] }; console.log(mapping); { '1': [], '2': [ 'a', 'b', 'c' ], '3': ...

Read More

Are the strings anagrams in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 231 Views

Two strings are said to be anagrams of each other if by rearranging, rephrasing or shuffling the letters of one string we can form the other string. Both strings must contain exactly the same characters with the same frequency. For example, 'something' and 'emosghtin' are anagrams of each other because they contain the same letters with the same count. We need to write a JavaScript function that takes two strings and returns true if they are anagrams of each other, false otherwise. Method 1: Character Frequency Count This approach counts the frequency of each character in ...

Read More

Subset with maximum sum in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 383 Views

In JavaScript, finding the subset of non-adjacent elements with maximum sum is a classic dynamic programming problem. We need to decide whether to include each element or skip it, ensuring no two adjacent elements are selected. The key insight is that for each element, we have two choices: include it (and skip the previous element) or exclude it (and take the maximum sum up to the previous element). Problem Statement Given an array of integers, find the subset of non-adjacent elements that produces the maximum sum. Adjacent elements cannot be selected together. For example, with the ...

Read More

Check if the string is a combination of strings in an array using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 263 Views

We are required to write a JavaScript function that takes in an array of strings as the first argument and a string as the second argument. The function should check whether the string specified by second argument can be formed by combining the strings of the array in any possible way. For example − If the input array is − const arr = ["for", "car", "keys", "forth"]; And the string is − const str = "forthcarkeys"; Then the output should be true, because the string is a combination of elements ...

Read More
Showing 2291–2300 of 8,010 articles
« Prev 1 228 229 230 231 232 801 Next »
Advertisements