Nikitasha Shrivastava

Nikitasha Shrivastava

163 Articles Published

Articles by Nikitasha Shrivastava

Page 7 of 17

Finding all the Longest Strings from an Array in JavaScript

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

In the given problem statement we have to find all the longest strings from an array with the help of JavaScript functionalities. This task can be done by getting the length of each string and then comparing these lengths with the maximum length. Understanding the Problem The problem is to find all the longest strings from an array in JavaScript. We have an array of strings and our task is to identify the strings with maximum length and return them as a new array. For example: if we have an array ['abc', 'defg', 'hijkl', 'mnopqr', 'stuvwxyz'], the longest ...

Read More

Algorithm to get the combinations of all items in array JavaScript

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

In this problem statement, our task is to get the combinations of all items in an array with the help of Javascript functionalities. We can use a recursive approach that iteratively adds items to a running list of combinations. Understanding the Problem The goal is to write a function in Javascript that finds all possible combinations of elements in an array. For example, if we have an array [1, 2, 3], the combinations would be: [ [], [1], [2], [3], [1, 2], [1, ...

Read More

Finding the largest prime factor of a number in JavaScript

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

In JavaScript, finding the largest prime factor of a number involves dividing the number by its prime factors until we reach the highest one. This is commonly solved using prime factorization. Understanding Prime Factors A prime factor is a prime number that divides the given number exactly (without remainder). For example, the number 84 has prime factors: 2, 2, 3, and 7. Among these, 7 is the largest prime factor. Algorithm Approach We use prime factorization by starting with ...

Read More

Random whole number between two integers JavaScript

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

In JavaScript, generating a random whole number between two integers is a common task that requires combining Math.random() with Math.floor() to ensure we get integers within the specified range. Understanding the Problem We need to create a function that returns a random integer between two given numbers (inclusive). For example, if we want a random number between 1 and 5, the possible outputs are: 1, 2, 3, 4, or 5. The Math.random() Method Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive). We need to transform this to get integers in our desired ...

Read More

Find the largest palindrome number made from the product of two n digit numbers in JavaScript

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

In this problem, we need to find the largest palindrome number that can be created by multiplying two n-digit numbers using JavaScript. We'll implement two functions: one to find the largest palindrome product and another to check if a number is palindromic. What are Palindrome Numbers? A palindrome number reads the same forwards and backwards. Examples include 44, 121, 202, 404, and 909. When reversed, these numbers remain identical to their original form. Understanding the Problem We need to find the largest possible palindrome that results from multiplying two n-digit numbers. For example, with 2-digit numbers ...

Read More

Sorting odd and even elements separately JavaScript

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

In JavaScript, we can sort odd and even positioned elements separately within an array while maintaining their relative positions. This approach sorts elements at even indices (0, 2, 4...) and odd indices (1, 3, 5...) independently. Understanding the Problem Given an array, we need to sort elements at even indices separately from elements at odd indices. For example, with array [9, 2, 7, 4, 5, 6, 3, 8, 1]: Even indices (0, 2, 4, 6, 8): [9, 7, 5, 3, 1] → sorted: [1, 3, 5, 7, 9] Odd indices (1, 3, 5, 7): [2, 4, ...

Read More

Smallest number that is divisible by first n numbers in JavaScript

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

Adding a unique id for each entry in JSON object in JavaScript

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

In this problem statement, our task is to add a unique id for every object entry in a JSON object with the help of JavaScript. We will use a loop and a variable to store the id for each object in the JSON object. Understanding the Problem Statement The problem statement is to write a function in JavaScript that adds a unique id to every item in the given JSON object. For example, if we have: let obj = { "entry1": {empName: "A", age: 25}, "entry2": {empName: "B", age: 30} ...

Read More

Finding the nth prime number in JavaScript

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

In this article, we'll learn how to find the nth prime number using JavaScript. A prime number is a positive integer greater than 1 that has no divisors other than 1 and itself. Understanding the Problem We need to create a JavaScript function that takes an input n and returns the nth prime number. For example, if n=5, we should return 11 (the 5th prime number in the sequence: 2, 3, 5, 7, 11). Algorithm Approach We'll use a two-step approach: Helper Function: Create an isPrime() function to check if a number is prime ...

Read More

How to get almost increasing sequence of integers in JavaScript ?

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

In JavaScript, an almost increasing sequence is a sequence where most elements are in non-decreasing order, with at most one element that breaks this pattern. This article demonstrates how to generate such sequences programmatically. Understanding the Problem An almost increasing sequence allows for exactly one "violation" where an element might be smaller than its predecessor. For example, [1, 3, 2, 5, 6] is almost increasing because only one element (2) breaks the increasing pattern. Our goal is to generate such sequences randomly in JavaScript. Algorithm Approach We'll create a function that generates a mostly increasing sequence ...

Read More
Showing 61–70 of 163 articles
« Prev 1 5 6 7 8 9 17 Next »
Advertisements