Object Oriented Programming Articles

Page 66 of 589

Group matching element in array in JavaScript

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

In JavaScript, grouping matching elements in an array is a common task that can be efficiently solved using the reduce() method. This approach allows us to iterate through an array and group consecutive duplicate elements together. What is the reduce() Function? The reduce() method is a built-in JavaScript function that processes each element of an array and accumulates a result. It takes a callback function with two main parameters: an accumulator (which stores the accumulated result) and the current value being processed. Basic reduce() Example const numbers = [1, 2, 3, 4, 5]; const sum ...

Read More

How to implement backtracking for a climbing stairs practice in JavaScript?

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

In the given problem statement we are asked to implement backtracking for a climbing stairs practice with the help of JavaScript functionalities. In data structures, backtracking is popularly known to explore all possible solutions. We can solve this problem with the help of a backtracking algorithm. What is the Backtracking Technique? Backtracking is a well-known algorithmic technique, which is basically used to solve problem statements that include searching for all possible solutions. It is based on a depth-first strategy and is used in combination with a recursive method. The basic ideology for this technique is to explore ...

Read More

Sorting an array including the elements present in the subarrays in JavaScript

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

In JavaScript, we often encounter arrays that contain nested subarrays and need to sort all elements together. This involves flattening the nested structure and then applying sorting algorithms. Understanding the Required Methods Before diving into solutions, let's understand the key JavaScript methods we'll use: sort() method: Sorts array elements in place. By default, it converts elements to strings and sorts alphabetically. For numeric sorting, we provide a comparison function: let numbers = [3, 1, 4, 1, 5, 9, 2, 6]; numbers.sort((a, b) => a - b); // ascending order console.log(numbers); [ 1, ...

Read More

Using BigInt to calculate long factorials in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 2K+ Views

In JavaScript, calculating factorials of large numbers requires the BigInt data type to avoid precision loss. BigInt handles arbitrarily large integers, making it perfect for computing long factorials that exceed JavaScript's standard number limits. What is BigInt? BigInt is a built-in JavaScript data type introduced in ECMAScript 2020 that represents integers of arbitrary size. Unlike the standard Number type, which has a maximum safe integer limit of 2^53 - 1, BigInt can handle infinitely large integers. // Regular numbers have limits console.log(Number.MAX_SAFE_INTEGER); // 9007199254740991 // BigInt can handle much larger values console.log(BigInt(Number.MAX_SAFE_INTEGER) * 100n); ...

Read More

Merging subarrays in JavaScript

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

This problem demonstrates how to merge subarrays containing email data by grouping emails under the same person's name. We'll use JavaScript's Set data structure to eliminate duplicates and organize the data efficiently. Understanding the Problem Given an array of subarrays where each subarray contains a person's name followed by their email addresses, we need to merge all emails belonging to the same person into a single subarray. For example, if "Ayaan" appears in multiple subarrays with different emails, we should combine all of Ayaan's emails into one subarray. Algorithm Step 1 − Create a function that ...

Read More

What is the best way to search for an item in a sorted list in JavaScript?

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

When searching for an item in a sorted array in JavaScript, binary search is the most efficient approach. Unlike linear search which checks every element, binary search takes advantage of the sorted order to eliminate half the search space with each comparison. What is Binary Search? Binary search is a divide-and-conquer algorithm that works on sorted arrays. It compares the target value with the middle element and eliminates half of the remaining elements at each step. This approach has O(log n) time complexity, making it much faster than linear search's O(n). How Binary Search Works The ...

Read More

JSON group object in JavaScript

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

In JavaScript, grouping JSON objects means organizing data by common properties or categories. This is useful for data analysis, filtering, and creating structured reports from collections of objects. What is JSON? JSON (JavaScript Object Notation) is a lightweight data format for transferring data between devices. JSON objects use key-value pairs where keys are strings and values can be strings, numbers, booleans, arrays, or nested objects. For example: {"name": "Alice", "age": 25}. const jsonData = [ { team: 'TeamA', score: 20 }, { ...

Read More

Make an array of another array\'s duplicate values in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 1K+ Views

In JavaScript, finding duplicate values between two arrays is a common task. This article demonstrates how to create an array containing elements that exist in both arrays using built-in array methods. What is an Array in JavaScript? An array is an object that stores multiple elements in a single variable. Arrays in JavaScript are ordered collections that can hold any data type and provide methods like filter() and indexOf() for manipulation. const array = [201, 202, 405]; Understanding the Logic To find duplicate values between two arrays, we use the filter() method on ...

Read More

Manipulate Object to group based on Array Object List in JavaScript

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

Grouping objects in JavaScript is a common operation when working with arrays of objects. This technique allows you to organize data by specific properties, making it easier to process and analyze related items together. Understanding the Problem Consider an array of objects representing people with properties like name, profession, and age. We want to group these objects by a specific property (like profession) to create an organized structure where each group contains all objects sharing that property value. For example, grouping people by profession would create separate arrays for developers, teachers, engineers, etc. This organization makes it ...

Read More

Manipulating objects in array of objects in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 4K+ Views

In JavaScript, manipulating objects within an array of objects is a common task. JavaScript provides several built-in array methods like map(), filter(), find(), and slice() to efficiently handle these operations. What is Object Manipulation in Arrays? Object manipulation in arrays involves three main operations: Updating - Modifying existing object properties Filtering - Selecting objects based on criteria Adding - Creating new objects or properties JavaScript provides methods like map(), filter(), find(), slice(), sort(), reduce(), and others to perform these manipulations efficiently. Original Array ...

Read More
Showing 651–660 of 5,881 articles
« Prev 1 64 65 66 67 68 589 Next »
Advertisements