Sakshi Jain

Sakshi Jain

12 Articles Published

Articles by Sakshi Jain

12 articles

Generating all possible permutations of array in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 4K+ Views

In JavaScript, generating all possible permutations of an array involves creating every unique arrangement of its elements. This is a common algorithmic problem that can be solved using recursion and array manipulation methods. What is Array Permutation? Array permutation refers to different arrangements of elements within an array. For an array with n elements, there are n! (factorial) possible permutations. Each permutation represents a unique ordering of the same elements. // Input array const arr = [1, 2, 3]; // All possible permutations ...

Read More

sorting array of numbers into sets in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 337 Views

In JavaScript, we often need to sort an array of numbers and convert it into a Set data structure. This process involves understanding how JavaScript's sort method works with numbers and how to properly convert arrays to Sets. Understanding JavaScript Arrays An array in JavaScript is a collection of elements stored under one roof. Unlike arrays in other languages, JavaScript arrays are objects with built-in properties and methods that make data manipulation easier. const arrayExample = [100, 200, 500, 600]; console.log(arrayExample); [100, 200, 500, 600] The Problem with JavaScript's Sort Method ...

Read More

Two sum problem in linear time in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 2K+ Views

The Two Sum Problem is a classic algorithmic challenge that asks us to find two numbers in an array that add up to a specific target value. This article demonstrates how to solve this problem efficiently in linear time using JavaScript. What is the Two Sum Problem? The Two Sum Problem requires finding a pair of indices in an array of numbers that add up to a given target sum. Given an array of integers and a target sum, we need to return the indices of two numbers that sum to the target value. The key constraint ...

Read More

Finding Common Item Between Arbitrary Number of Arrays in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 390 Views

Finding common elements among multiple arrays is a frequent requirement in JavaScript programming. This problem involves identifying elements that appear in every array within a collection of arrays. What are Arbitrary Number of Arrays An arbitrary number of arrays refers to any collection of multiple arrays (more than two) where we need to find intersection elements. These arrays can contain random elements and are typically organized as an array of arrays or nested data structure. // Example: Array of arrays const arrayCollection = [ [1, 2, 3, 4], [2, 3, 5, 6], ...

Read More

Can the string be segmented in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 421 Views

The string segmentation problem determines if a given string can be broken down into words that exist in a provided dictionary. This is a classic dynamic programming problem with practical applications in natural language processing and text analysis. What is String Segmentation? String segmentation involves breaking a continuous string into meaningful words using a dictionary. For example, given the string "haveapplepie" and dictionary ["have", "apple", "pie"], we can segment it as "have" + "apple" + "pie". // Example visualization const dictionary = ["apple", "have", "pie"]; const input = "haveapplepie"; // Can be segmented as: "have" + ...

Read More

Case-sensitive sort in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 2K+ Views

JavaScript's default sort() method performs case-sensitive sorting but places uppercase letters before lowercase letters. This article demonstrates how to implement true case-sensitive sorting where special characters and numbers come first, followed by lowercase letters, then uppercase letters. JavaScript Case Sensitivity JavaScript is case-sensitive, meaning it treats uppercase and lowercase letters as completely different characters. const language = "JavaScript"; const Language = "React"; const x = 100; console.log(language); console.log(Language); console.log(x); JavaScript React 100 Default Sort Behavior JavaScript's sort() method converts elements to strings and sorts by UTF-16 character codes. By ...

Read More

Removing duplicates from a sorted array of literals in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 342 Views

When working with sorted arrays in JavaScript, removing duplicates is a common operation. Since the array is already sorted, duplicate elements appear consecutively, making the removal process more efficient. What is a Sorted Array? A sorted array is an array where elements are arranged in a specific order (ascending or descending). In JavaScript, this ordering makes it easier to identify and remove duplicate elements since identical values are grouped together. const sortedArray = [1, 2, 2, 3, 4, 6, 6]; // After removing duplicates const uniqueArray = [1, 2, 3, 4, 6]; Method 1: ...

Read More

Add all records from one array to each record from a different array in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 582 Views

In JavaScript, you may need to combine elements from two arrays where each record from one array pairs with every record from another array. This creates a Cartesian product - every possible combination of elements from both arrays. What is a Cartesian Product? A Cartesian product is a mathematical concept where given two sets A and B, A × B represents every possible combination of elements from both sets. In JavaScript, this translates to pairing each element from the first array with every element from the second array. For example, given two arrays: const array1 ...

Read More

Inverting a binary tree in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 888 Views

Inverting a binary tree means creating a mirror image where all left and right child nodes are swapped recursively. This is a classic tree manipulation problem that demonstrates recursion and tree traversal concepts. What is a Binary Tree? A binary tree is a hierarchical data structure where each node has at most two children: left and right. The topmost node is called the root, and nodes with no children are called leaves. 4 2 7 ...

Read More

Delete elements in first string which are not in second string in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 206 Views

The problem statement asks us to delete elements from the first string that are not present in the second string. In other words, we need to keep only the characters from the first string that also exist in the second string, while preserving their original order. This problem can be viewed as finding the intersection of characters between two strings and returning a filtered version of the first string containing only common characters. What is a Map in JavaScript? We'll use a Map data structure to efficiently solve this problem. A Map is a collection of key-value ...

Read More
Showing 1–10 of 12 articles
« Prev 1 2 Next »
Advertisements