Found 6683 Articles for Javascript

Group a sorted array based on the difference between current and previous elements in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:10:05

355 Views

In the given problem statement we have to group a sorted array based on the difference between the current and previous elements with the help of Javascript functionalities. To group a sorted array based on the difference between the current and previous items we can iterate over the array and create a new array of groups. Understanding the Problem Statement The above problem statement states that we have to find out the group of elements based on the difference between the current and previous elements in the array. As we have given a sorted array so we need ... Read More

Highest and lowest value difference of array JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:14:24

405 Views

In this problem we have to create an algorithm to get the highest and lowest value difference of an array with the help of Javascript functionality. So we will solve the problem with for loop and initialization of highest and lowest values to Infinity. Understanding the logic of the problem statement The problem statement is asking to write the code for getting the highest and lowest value difference of the array. So for solving this task we will initialize two variables, these variables will store the highest and lowest values. And then iterate through every element ... Read More

JavaScript Sum odd indexed and even indexed elements separately and return their absolute difference

Nikitasha Shrivastava
Updated on 14-Aug-2023 18:32:35

1K+ Views

In this problem we will understand how to get the absolute difference of the sum of odd indexed and even indexed items separately with the help of Javascript functionalities. We will use a simple loop to iterate through all the elements of the array. Understanding the problem statement To understand the above problem statement we will break down the problem step by step: So we are given an array of numbers. Our task is to separate the items in the array in two groups: first ... Read More

Average with the Reduce Method in JavaScript

AmitDiwan
Updated on 11-Aug-2023 16:14:19

727 Views

In the given problem statement, our aim is to get the average of all the items with the help of the reduce method of Javascript. So for doing this task we will create a function and give an array as a parameter. Understanding the problem statement We have given a task to calculate the average value of the given items in the array. And we have to use the reduce method which is a predefined method of Javascript. For example if we have an array as [1, 2, 3, 4, 5], so the average value of the ... Read More

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

Nikitasha Shrivastava
Updated on 16-Aug-2023 16:30:24

325 Views

In this problem statement our aim is to write an algorithm to remove duplicate items from an array with a function with the help of Javascript functionalities. Understanding the problem statement In the above problem statement we have to create a function by which we can accept an array as a parameter and give a new array to store the unique items from the given input array and without including the identical values. For example - suppose we have an array as [0, 0, 2, 2, 3, 3] so after removing the duplicate numbers we will have ... Read More

Convert string with separator to array of objects in JavaScript

Nikitasha Shrivastava
Updated on 14-Aug-2023 15:22:37

243 Views

In this article we will discuss algorithm and complexity for converting string with separator to array of objects with the help of Javascript functionalities. For doing this task we will use split and map functions of Javascript. Understanding the problem statement The problem statement says to write a function which can convert a given string with the given separator into an array of objects in Javascript. For example, if we have a string "name1, name2, name3" and a separator ", " then we have to convert these strings into an array of objects which looks like: [{value: ... Read More

Round number down to nearest power of 10 JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 15:52:47

677 Views

In the provided problem statement, our task is to write the function for partial sum in an array of arrays with the help of Javascript. So here we will be given a variety of arrays and we need to compute the sum of each row and show the result. Understanding the problem statement The problem statement is asking for creating a function in Javascript which rounds down a given input number to the nearest power of 10. For example if there is an input 1365 so the output should be 1000. That is the nearest power of 10 which is ... Read More

Get all substrings of a string in JavaScript recursively

Nikitasha Shrivastava
Updated on 18-May-2023 13:53:48

2K+ Views

In the provided problem statement, our aim is to get all substrings of a string recursively with the help of Javascript. So here we will be creating a recursive function that can generate all possible substrings of a given input string. Understanding the problem statement The problem statement is asking us to create a recursive function which can generate all the possible substrings of a given input string with the help of Javascript. A substring is any continuous sequence of characters within the input string. For example: input strings “xy" so the possible substrings are "x", "y", and "xy". Algorithm ... Read More

Masking a string JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 14:57:33

4K+ Views

The above problem statement is about masking a substring within a string with the help of asterisks in Javascript. So we have to create a function to get the string with some hidden characters. Understanding the problem statement In the above problem statement we have to mask a substring within a string with the help of asterisks in Javascript. Masking a given string means we have to replace the certain characters in the given string with some other characters. Normally the asterisks used to hide sensitive information such as passwords, credit card numbers and other confidential data. Logic for the ... Read More

Retrieve key and values from object in an array JavaScript

Nikitasha Shrivastava
Updated on 16-Aug-2023 16:35:56

6K+ Views

In the given problem we are required to retrieve the key and values from an object in an array with the help of Javascript. So here we will retrieve the keys and values from an object in an array with the help of two methods provided by the object class in Javascript. Understanding the Problem Statement The problem statement is to retrieve the keys and values from a given object in an array with the help of Javascript. So in Javascript the object is a collection of properties in which every property is a key and value pair. ... Read More

Advertisements