Object Oriented Programming Articles

Page 65 of 589

Can the string be segmented in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 432 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

Finding Common Item Between Arbitrary Number of Arrays in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 406 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

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

Removing duplicates from a sorted array of literals in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 358 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

sorting array of numbers into sets in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 348 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

Determining whether numbers form additive sequence in JavaScript

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

This problem asks us to determine if the given numbers in an array form an additive sequence. An additive sequence is one where each number (starting from the third) equals the sum of the two preceding numbers. Understanding Additive Sequences An additive sequence must have at least three numbers. Each consecutive number in the series, except the first two, must equal the sum of the two numbers before it. // Example: 112358 as a string of digits // 1 + 1 = 2 // 1 + 2 = 3 // 2 + 3 = ...

Read More

Fibonacci like sequence in JavaScript

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

In JavaScript, you can generate a Fibonacci-like sequence using various approaches including loops and recursion. The Fibonacci sequence is fundamental in programming and demonstrates different algorithmic techniques. What is the Fibonacci Sequence? The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding numbers. The sequence starts with 0 and 1, then continues as: 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. Formula: F(n) = F(n-1) + F(n-2), where F(0) = 0 and F(1) = 1 Method 1: Generate Fibonacci Up to a Certain Number ...

Read More

Get value for key from nested JSON object in JavaScript

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

In JavaScript, accessing values from nested JSON objects is a common task when working with APIs and complex data structures. We can retrieve nested values using dot notation, bracket notation, or custom functions. Before exploring different approaches, let's understand what JSON and nested JSON objects are: What is JSON and Nested JSON Objects? JSON (JavaScript Object Notation) is a lightweight, text-based format for representing structured data. It's widely used for data transmission between web applications and servers. Nested JSON objects contain objects within other objects, creating a hierarchical structure. Each nested property has a unique path ...

Read More
Showing 641–650 of 5,881 articles
« Prev 1 63 64 65 66 67 589 Next »
Advertisements