Articles on Trending Technologies

Technical articles with clear explanations and examples

How to remove duplicate property values in array – JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 865 Views

In JavaScript, you may need to remove duplicate values from array properties within an array of objects. This is common when working with data that contains repeated values that should be unique. Problem Example Consider an array of student objects where some students have duplicate marks in their studentMarks array: var details = [ { studentName: "John", studentMarks: [78, 98] }, { ...

Read More

Remove item from a nested array by indices in JavaScript

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

Suppose we have a nested array of objects like this: const arr = [ { value: 'some value' }, { array: [ { value: 'some value' }, { array: [ ...

Read More

JavaScript function that generates all possible combinations of a string

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 851 Views

We are required to write a JavaScript function that takes in a string as the only argument. The function should generate an array of strings that contains all possible combinations of characters from the string. Understanding the Problem The function uses a bitwise approach to generate all possible combinations. It first extracts individual characters, then uses binary representation to determine which characters to include in each combination. Example Following is the code − const str = 'Delhi'; const allCombinations = (str1 = '') => { const arr = []; ...

Read More

Finding minimum absolute difference within a Binary Search Tree in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 268 Views

We are required to write a JavaScript function that takes in the root of a BST that holds some numerical data like this: 1 \ 3 / 2 The function should return the minimum absolute difference between any two nodes of the tree. For the above tree, the output should be: const output = 1; because |1 - 2| = |3 - 2| = 1 Understanding ...

Read More

Uneven sorting of array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 273 Views

We need to write a JavaScript function that sorts an array in a zigzag pattern where elements alternate between smaller and larger values: arr[0] < arr[1] > arr[2] < arr[3]... Problem Statement Given an array of numbers, we want to rearrange it so that: Even indices (0, 2, 4...) have smaller values Odd indices (1, 3, 5...) have larger values The pattern creates a "wave" or zigzag effect For example, if the input array is [1, 5, 1, 1, 6, 4], a valid output could be [1, 6, 1, 5, 1, 4]. Solution Approach ...

Read More

Counting rings in letters using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 259 Views

We need to write a JavaScript function that counts the number of rings (closed loops) present in letters of a string. Different letters contain different numbers of rings based on their visual structure. Understanding Letter Rings Letters with rings are those that contain closed loops in their visual representation: One ring: A, D, O, P, Q, R, a, b, d, e, g, o, p, q Two rings: B (has two closed loops) No rings: All other letters Example Implementation const str = 'some random text string'; function countRings(str) { ...

Read More

Sorting and find sum of differences for an array using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 404 Views

Problem We need to write a JavaScript function that takes an array of integers, sorts them in descending order, and then calculates the sum of differences between consecutive pairs. For example, if the array is: [6, 2, 15] After sorting in descending order: [15, 6, 2] The sum of differences would be: (15 - 6) + (6 - 2) = 9 + 4 = 13 Solution Here's the implementation that sorts the array and calculates the sum of consecutive differences: const arr = [6, 2, 15]; ...

Read More

Difference between JavaScript and AngularJS

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 5K+ Views

JavaScript is a scripting language that is used to generate dynamic HTML pages with interactive effects on a webpage that runs in the web browser of the client. On the other hand, Angular JS is a framework that is built on JavaScript and adds new functionalities to HTML. Its primary purpose is to facilitate the creation of dynamic and single-page web applications (SPAs). In this article, we are going to highlight the differences between Angular JS and JavaScript. Let's start with a basic understanding of JavaScript and AngularJS. What is JavaScript? JavaScript is a simple programming language ...

Read More

How to wrap setTimeout() method in a promise?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 8K+ Views

The setTimeout() method executes code or functions after a specified delay in milliseconds. When working with promises, you can wrap setTimeout() to create delayed asynchronous operations that resolve or reject after a specific time period. In JavaScript, a promise is an object that represents the eventual completion of an asynchronous operation. Here, we will learn to resolve or reject promises after some delay using the setTimeout() method. Basic Promise Without setTimeout() First, let's see a basic promise that resolves immediately without any delay: Using Promises without setTimeout() method ...

Read More

Recursive string parsing into object - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 598 Views

Recursive string parsing transforms an array of dot-separated strings into a nested JavaScript object structure. This technique is useful for converting flat configuration paths into hierarchical data structures. Problem Description Given an array of strings following the pattern x.y.x.y..., we need to create a nested object where the last segment becomes a value in an array, and preceding segments form the nested structure. For example, if the input array is: const arr = [ "country.UK.level.1", "country.UK.level.2", "country.US.level.1", "country.UK.level.3" ...

Read More
Showing 16241–16250 of 61,297 articles
Advertisements