Nikitasha Shrivastava

Nikitasha Shrivastava

163 Articles Published

Articles by Nikitasha Shrivastava

Page 14 of 17

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

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

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

Given an array of integers return positives, whose equivalent negatives present in it in JavaScript

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

In this problem, we need to find positive integers from an array that have their corresponding negative counterparts present in the same array. For example, if we have [1, -1, 2, -3, 4, -4], we should return [1, 4] since both 1 and 4 have their negatives (-1 and -4) in the array. Understanding the Problem Given an array of integers containing both positive and negative values, we need to identify positive numbers whose negative equivalents also exist in the array. For instance, in the array [7, ...

Read More

Group matching element in array in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 396 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

Non-negative set subtraction in JavaScript

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

In JavaScript, non-negative set subtraction involves removing elements from one set that exist in another set, while ensuring the result contains only non-negative values. This operation combines set theory with value filtering using JavaScript's built-in Set object and forEach method. What is the Set Object? The Set is a built-in data structure introduced in ES6 that stores unique values of any type. Unlike arrays, Sets automatically eliminate duplicates and maintain insertion order. Key characteristics include: Uniqueness: Only unique elements are stored ...

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

Maximum decreasing adjacent elements in JavaScript

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

In JavaScript, finding the maximum number of decreasing adjacent elements means identifying the longest consecutive sequence where each element is smaller than the previous one. This is essentially finding the longest decreasing subarray. Understanding the Problem We need to find the maximum count of consecutive decreasing pairs in an array. For example, in array [5, 4, 3, 2, 1], we have 4 decreasing pairs: (5, 4), (4, 3), (3, 2), and (2, 1). Finding Decreasing Adjacent Elements 5 arr[0] ...

Read More

Generating desired combinations in JavaScript

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

In JavaScript, generating combinations that sum to a target value is a common programming challenge. This problem involves finding all unique combinations of integers from 1 to 9 with a specific length that sum to a target value. Understanding the Problem We need to generate combinations where: m represents the size of each combination n represents the target sum Each combination uses unique numbers from 1 to 9 For example, if m = 3 and n = 9, valid combinations include [1, 2, 6], [1, 3, 5], and [2, ...

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
Showing 131–140 of 163 articles
Advertisements