Articles on Trending Technologies

Technical articles with clear explanations and examples

Finding the group with largest elements with same digit sum in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 194 Views

We are required to write a JavaScript function that takes in a positive integer, say n, as the only argument. The function should first group the integers from 1 to n into subarrays where each subarray contains all elements with the same digit sum. Then the function should examine each subarray and return the length of the largest group (the group with the most elements). Understanding Digit Sum The digit sum is calculated by adding all digits of a number. For example: Digit sum of 15 = 1 + 5 = 6 Digit sum of 23 ...

Read More

Inverting signs of integers in an array using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 294 Views

Problem We are required to write a JavaScript function that takes in an array of integers (negatives and positives). Our function should convert all positives to negatives and all negatives to positives and return the resulting array. Method 1: Using for Loop The traditional approach uses a for loop to iterate through each element and multiply by -1 to invert the sign: const arr = [5, 67, -4, 3, -45, -23, 67, 0]; const invertSigns = (arr = []) => { const res = []; for(let i = ...

Read More

What are JavaScript Classes and Proxies?

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 268 Views

JavaScript Classes and Proxies are powerful ES6+ features that enhance object-oriented programming and metaprogramming capabilities. Classes provide a cleaner syntax for creating objects and implementing inheritance, while Proxies allow you to intercept and customize operations on objects. JavaScript Classes Classes in JavaScript are syntactic sugar over the existing prototype-based inheritance. They use the class keyword instead of functions and must be declared before use, unlike function declarations which are hoisted. Class Declaration Syntax class ClassName { constructor(property1, property2) { this.property1 = property1; ...

Read More

How to convert array of strings to array of numbers in JavaScript?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 30K+ Views

In JavaScript, there are different ways to convert an array of strings to an array of numbers. The most common approaches include using the built-in parseInt() method, the Number() constructor, and the unary + operator. Using the parseInt() Method The parseInt() method is a built-in function in JavaScript that takes a string as an argument and returns an integer. This method can be used with the map() method to convert an array of strings to an array of numbers. Syntax parseInt(string, radix); Parameters ...

Read More

Enter values with prompt and evaluate on the basis of conditions in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 299 Views

JavaScript's prompt() function allows you to collect user input and evaluate it using conditional statements. This is useful for creating interactive web applications that respond based on user-provided values. Basic Syntax To get user input and convert it to a number: var value = parseInt(prompt("Enter a value")); Example: Conditional Evaluation Based on User Input Here's a complete example that prompts for two values and evaluates their product: Prompt and Evaluate ...

Read More

Sorting an array of literals using quick sort in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 459 Views

We are required to write a JavaScript function that takes in an array of numbers and uses the quick sort algorithm to sort it. QuickSort Algorithm QuickSort is a divide-and-conquer algorithm that works by selecting a 'pivot' element from the array and partitioning other elements into two sub-arrays according to whether they are less than or greater than the pivot. The sub-arrays are then sorted recursively. How QuickSort Works The algorithm follows these steps: Choose a pivot element from the array (typically the middle element) Partition the ...

Read More

Dynamic Programming: Is second string subsequence of first JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

We are given two strings str1 and str2, we are required to write a function that checks if str1 is a subsequence of str2. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. For example, "ace" is a subsequence of "abcde" while "aec" is not because the relative order is not maintained. Understanding Subsequences In a subsequence, characters must appear in the same order as in the original string, but they ...

Read More

How to build a string with no repeating character n separate list of characters? in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 473 Views

When working with multiple arrays of characters, we often need to create combinations where each string contains exactly one character from each array with no duplicate characters. This is useful for generating unique combinations while avoiding repeated letters that might exist across different arrays. Problem Overview Given multiple arrays of characters, we need to build all possible strings that: Contains exactly one letter from each array ...

Read More

Finding Lucky Numbers in a Matrix in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 974 Views

In the given problem statement we have to write a function to get the lucky numbers in a matrix with the help of Javascript. A lucky number is defined as an element that is the minimum value in its row and the maximum value in its column. Understanding the Problem Statement A lucky number in a matrix must satisfy two conditions: It is the minimum element in its row It is the maximum element in its column For example, in the matrix [[3, 7], [9, 11]], the number 7 ...

Read More

divisibleBy() function over array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 201 Views

Problem We are required to write a JavaScript function that takes in an array of numbers and a single number as two arguments. Our function should filter the array to contain only those numbers that are divisible by the number provided as second argument and return the filtered array. Example Following is the code − const arr = [56, 33, 2, 4, 9, 78, 12, 18]; const num = 3; const divisibleBy = (arr = [], num = 1) => { const canDivide = (a, b) => a % ...

Read More
Showing 16551–16560 of 61,297 articles
Advertisements