Object Oriented Programming Articles

Page 62 of 589

Parse and balance angle brackets problem in JavaScript

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

In JavaScript, determining whether angle brackets in a string are properly balanced is a common problem when working with HTML, XML, or template parsing. This problem requires checking that every opening angle bracket '' in the correct order. What is a Stack-based Approach? The stack-based approach uses a Last In, First Out (LIFO) data structure to track opening brackets. When we encounter an opening bracket, we push it onto the stack. When we find a closing bracket, we check if there's a matching opening bracket at the top of the stack and pop it if found. Think ...

Read More

Partial sum in array of arrays JavaScript

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

In the given problem statement our task is to get the partial sum in an array of arrays with the help of JavaScript functionalities. The partial sum at position (i, j) represents the sum of all elements from the top-left corner (0, 0) to the current position (i, j). Understanding the Problem An array of arrays (2D array) is a data structure where each element is itself an array. For example: [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] The partial ...

Read More

Pick out numbers from a string in JavaScript

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

In JavaScript, extracting numbers from strings is a common task that can be efficiently accomplished using regular expressions and built-in string methods. This approach allows you to find and extract numeric values from mixed content. Understanding the Problem The goal is to extract all numeric values from a given string. For example, from the string "I am 25 years old and earn $1500.50", we want to extract [25, 1500.50]. This involves pattern matching to identify numeric sequences including integers and decimal numbers. Using Regular Expressions with match() ...

Read More

Remove duplicate items from an array with a custom function in JavaScript

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

In JavaScript, arrays often contain duplicate values that need to be removed. This article demonstrates how to create a custom function to eliminate duplicates and return an array with unique elements only. Understanding the Problem We need to create a function that accepts an array as input and returns a new array containing only unique items, excluding any duplicates. For example, given the array [0, 0, 2, 2, 3, 3], the function should return [0, 2, 3]. Algorithm Overview The algorithm iterates through the input array and adds items to a result array only if they ...

Read More

Retrieve key and values from object in an array JavaScript

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

In JavaScript, extracting keys and values from objects within an array is a common task when processing data structures. This can be accomplished using built-in Object methods like Object.keys() and Object.values(). Understanding the Problem When working with arrays of objects, you often need to access both the property names (keys) and their corresponding values. JavaScript objects are collections of key-value pairs, and the Object class provides methods to extract this information efficiently. Using Object.keys() and Object.values() The Object.keys() method returns an array of property names, while Object.values() returns an array of property values from an object. ...

Read More

Shift strings Circular left and right in JavaScript

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

The main objective for the problem statement is to perform a circular shift on the strings in Javascript. The circular shifts can be left shift or right shift. And implement this solution in Javascript. Understanding the Problem The problem at hand is to shift the strings circularly left and right with the help of Javascript functionalities. Circular shifting means we have to move the characters of the given string in a circular manner in which the characters that are to be shifted beyond the boundaries of the string should reappear at the opposite end. Logic for the ...

Read More

Shortest distance between objects in JavaScript

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

In JavaScript, calculating the shortest distance between two objects requires their coordinates and the Euclidean distance formula. This is commonly used in game development, mapping applications, and geometric calculations. Understanding the Problem To find the shortest distance between two objects, we need their position coordinates (x, y). The distance is calculated using the Euclidean distance formula: √[(x₂-x₁)² + (y₂-y₁)²] The Distance Formula The Euclidean distance formula calculates the straight-line distance between two points in a coordinate system: ...

Read More

Smallest number that is divisible by first n numbers in JavaScript

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

In this problem, we need to find the smallest number that is divisible by all numbers from 1 to n. This is essentially finding the Least Common Multiple (LCM) of the first n natural numbers. Understanding the Problem The problem requires finding the smallest positive integer that is evenly divisible by each of the numbers from 1 to n without any remainder. For example, if n = 4, we need the smallest number divisible by 1, 2, 3, and 4, which is 12. Logic and Approach We solve this using the Least Common Multiple (LCM) concept. ...

Read More

Sort an integer array, keeping first in place in JavaScript

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

In JavaScript, when you need to sort an integer array while keeping the first element in its original position, you can combine array slicing with the built-in sort method. This approach preserves the first element while sorting the remaining elements. Understanding the Problem The task is to sort an integer array in ascending order while keeping the first element at index 0. For example, if you have an array [4, 7, 8, 5, 6, 1, 3], the result should be [4, 1, 3, 5, 6, 7, 8] ...

Read More

Sorting according to weights of numbers in JavaScript

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

In this problem, we need to sort an array of numbers according to their weights using JavaScript. The weight of a number is defined as the sum of its digits, and we'll create functions to calculate weights and perform the sorting. Understanding the Problem We have to sort numbers according to their weights, where a weight is the sum of a number's digits. For example, if we have an array [19, 11, 12, 15]: Weight of 19 = 1 + ...

Read More
Showing 611–620 of 5,881 articles
« Prev 1 60 61 62 63 64 589 Next »
Advertisements