Nikitasha Shrivastava

Nikitasha Shrivastava

163 Articles Published

Articles by Nikitasha Shrivastava

Page 15 of 17

Generating desired combinations in JavaScript

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

How to split sentence into blocks of fixed length without breaking words in JavaScript

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

In JavaScript, splitting a sentence into blocks of fixed length while keeping words intact requires careful handling of word boundaries. This ensures readability by avoiding broken words across blocks. Understanding the Problem We need to split a sentence into chunks of a specified maximum length without breaking words. Each block should contain complete words only, and if adding a word would exceed the length limit, that word starts a new block. For example, with the sentence "You are reading this article on Tutorials point website" and block length 15, the output should be: ['You are ...

Read More

Sorting an array including the elements present in the subarrays in JavaScript

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

In JavaScript, we often encounter arrays that contain nested subarrays and need to sort all elements together. This involves flattening the nested structure and then applying sorting algorithms. Understanding the Required Methods Before diving into solutions, let's understand the key JavaScript methods we'll use: sort() method: Sorts array elements in place. By default, it converts elements to strings and sorts alphabetically. For numeric sorting, we provide a comparison function: let numbers = [3, 1, 4, 1, 5, 9, 2, 6]; numbers.sort((a, b) => a - b); // ascending order console.log(numbers); [ 1, ...

Read More

Calculating the average for each subarray separately and then return the sum of all the averages in JavaScript

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

In JavaScript, when working with arrays of subarrays, we often need to calculate the average for each subarray separately and then return the sum of all these averages. This can be efficiently accomplished using JavaScript's built-in array methods like reduce(). What is the reduce() Method in JavaScript? The reduce() method in JavaScript reduces an array to a single value by iterating over each element and applying a callback function that accumulates a value based on each iteration. It takes two main arguments: an accumulator (the accumulated value from previous iterations) and the current value being processed. ...

Read More

Calculate the difference between the first and second element of each subarray separately and return the sum of their differences in JavaScript

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

In JavaScript, we often need to process arrays of subarrays and perform calculations on their elements. This article demonstrates how to calculate the difference between the first and second element of each subarray and return the sum of all differences. What is an Array of Subarrays? An array of subarrays (or nested array) is an array that contains other arrays as its elements. Each inner array is called a subarray. const array = [[1, 2], [4, 5], [7, 8]]; console.log(array[0]); // First subarray console.log(array[1][0]); // First element of second subarray ...

Read More

Fibonacci like sequence in JavaScript

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

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

How to implement backtracking for a climbing stairs practice in JavaScript?

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

In the given problem statement we are asked to implement backtracking for a climbing stairs practice with the help of JavaScript functionalities. In data structures, backtracking is popularly known to explore all possible solutions. We can solve this problem with the help of a backtracking algorithm. What is the Backtracking Technique? Backtracking is a well-known algorithmic technique, which is basically used to solve problem statements that include searching for all possible solutions. It is based on a depth-first strategy and is used in combination with a recursive method. The basic ideology for this technique is to explore ...

Read More

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
Showing 141–150 of 163 articles
Advertisements