Front End Technology Articles

Page 220 of 652

The algorithm problem - Backtracing pattern in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 274 Views

Backtracking is a powerful algorithmic pattern for solving constraint satisfaction problems. In this grid path problem, we need to find all possible paths from start to end that visit every walkable square exactly once. Problem Definition Given a 2D grid with different square types, find the number of unique paths from start to end: 1 represents the starting square (exactly one) 2 represents the ending square (exactly one) 0 represents empty squares we can walk over -1 represents obstacles we cannot walk over ...

Read More

Filter unique array values and sum in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 786 Views

In JavaScript, you may need to filter arrays that contain duplicate values and combine their numeric values. This is common when processing data like product orders, transactions, or inventory records. Problem Statement Given an array of arrays where each subarray has three elements [id, name, amount], we need to: Remove duplicate entries based on the first element (id) Sum the third element (amount) for matching entries const arr = [[12345, "product", "10"], [12345, "product", "15"], [1234567, "other", "10"]]; The expected output should combine the duplicate entries and sum their amounts: ...

Read More

Group all the objects together having the same value for the '_id' key in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 411 Views

Suppose we have an array of objects like this − const arr = [ {_id : "1", S : "2"}, {_id : "1", M : "4"}, {_id : "2", M : "1"}, {_id : "" , M : "1"}, {_id : "3", S : "3"} ]; We are required to write a JavaScript function that takes in one such array and groups all the objects together that have the same value for the '_id' key. Therefore, the final output should ...

Read More

How to create a third object from two objects using the key values in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 258 Views

In JavaScript, you can create a third object from two objects by mapping key values between them. This is useful when you have one object containing arrays of keys and another object with corresponding values. Problem Statement Given two objects where the first contains arrays of keys and the second contains key-value pairs, we need to calculate totals for each category: const obj1 = { positive: ['happy', 'excited', 'joyful'], negative: ['depressed', 'sad', 'unhappy'] }; const obj2 = { happy: 6, excited: 1, unhappy: 3 }; ...

Read More

Get intersection between two ranges in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 897 Views

In JavaScript, finding the intersection between two numerical ranges involves determining the overlapping portion. A range is typically represented as an array with two elements: [start, end]. Understanding Range Intersection The intersection of two ranges is the overlapping segment. For ranges [2, 5] and [4, 7], the intersection is [4, 5] because that's where they overlap. const arr1 = [2, 5]; const arr2 = [4, 7]; console.log("Range 1:", arr1); console.log("Range 2:", arr2); Range 1: [ 2, 5 ] Range 2: [ 4, 7 ] Algorithm To find the intersection, we ...

Read More

How to add float numbers using JavaScript?

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

In JavaScript, floating-point numbers can be added directly using the addition operator (+). The parseFloat() function converts strings to floating-point numbers, but is not required when working with numeric literals. Example 1: Direct Addition The simplest way to add float numbers is using the addition operator directly: let inputFloat1 = 2.3; let inputFloat2 = 3.5; console.log("The two float values are:", inputFloat1, "and", inputFloat2); let result = inputFloat1 + inputFloat2; console.log("The sum of the float values is:", result); The two float values are: 2.3 and 3.5 The sum of the float values ...

Read More

Check for a self-dividing number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 305 Views

A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is self-dividing because it's divisible by 1, 2, and 8. However, any number containing 0 cannot be self-dividing since division by zero is undefined. What Makes a Number Self-Dividing? A number qualifies as self-dividing if: It contains no zeros (since division by zero is impossible) The number is evenly divisible by each of its individual digits Examples 128: Self-dividing because 128 ÷ 1 = 128, 128 ÷ 2 = ...

Read More

Palindrome numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 784 Views

We are required to write a JavaScript function that takes in a number and determines whether or not it is a palindrome number. Palindrome numbers − A palindrome number is that number which reads the same from both left and right sides. For example − 343 is a palindrome number 6789876 is a palindrome number 456764 is not a palindrome number Method 1: String Reversal Approach The simplest approach is to convert the number to a string, reverse it, and compare ...

Read More

Compare keys & values in a JSON object when one object has extra keys in JavaScript

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

When comparing JSON objects in JavaScript, you often need to check if the common keys have matching values, even when one object has extra properties. This is useful for validating partial object matches or checking if one object is a subset of another. Problem Statement Consider these two objects: const obj1 = {a: "apple", b: "banana", c: "carrot"}; const obj2 = {a: "apple", e: "egg", b: "banana", c: "carrot", d: "dog"}; We need a function that returns true because all common keys (a, b, c) have matching values, ignoring the extra keys (e, d) ...

Read More

Remove duplicates from array with URL values in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 492 Views

Suppose, we have an array of objects like this − const arr = [ { url: 'www.example.com/hello', id: "22" }, { url: 'www.example.com/hello', id: "22" }, { url: 'www.example.com/hello-how-are-you', id: ...

Read More
Showing 2191–2200 of 6,519 articles
« Prev 1 218 219 220 221 222 652 Next »
Advertisements