Found 6710 Articles for Javascript

How to write the factorial function with reduce and range in JavaScript?

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

1K+ Views

In this problem statement, our aim is to write the factorial function with reduce and range with the help of Javascript. So basically range and reduce are the predefined functions of Javascript. What is the use of reduce and range functions in Javascript ? In Javascript the reduce and range functions are the most useful function when working with arrays. The reduce function takes an array and reduces it to a single value by processing a function for every item of the array. The function takes two parameters, the first one is the accumulator which stores the result of ... Read More

JavaScript - How to create nested unordered list based on nesting of array?

Nikitasha Shrivastava
Updated on 18-May-2023 14:37:59

3K+ Views

In this problem statement, our task is to to create a nested unordered list based on nesting of arrays with the help of Javascript. So for doing this task we will use a function to call recursively for each nested array and create a new unordered list.. Understanding the problem statement In the above problem statement we have to create a function for a nested list in HTML using Javascript. The input for the code will be an array that can have any number of items and can also include other arrays that represent nested lists. The code will be ... Read More

Recursive loop that prints an inverted count in JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 15:36:10

422 Views

In the given problem statement, we have to print an inverted count with a recursive loop and code with the help of Javascript. So basically we have to print the count in inverted count or we can say in descending order. What is Recursive technique ? The recursive technique is an approach that involves solving a problem by breaking it into smaller pieces of the same problem till a base case is reached. This function calls itself with different arguments in order to achieve the required output. This is commonly used when the solution to a problem depends on ... Read More

Sorting strings with decimal points in JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 15:59:45

1K+ Views

In this problem statement, our aim is to sort strings with decimal points with the help of Javascript functionalities. So for doing this task we will use the sort and map method of Javascript. Understanding the problem statement The problem statement is to write a function in Javascript by which we can sort the given strings with decimal points. For example if we have an array of strings like [‘3.3’, ‘4.4’, ‘2.3’, ‘1.2’] so our task is to sort the given array of strings. But for sorting these strings first we need to convert it into numbers. After converting ... Read More

JavaScript - find distance between items on array

AmitDiwan
Updated on 25-Nov-2020 06:49:52

326 Views

Suppose, we have a sorted (increasing order) array of Numbers like this −const arr = [2, 5, 7, 8, 9];We are required to write a JavaScript function that takes in one such array. The function should construct a new subarray for each element of the input array.The sub-array should contain the difference (difference between that very element and the succeeding elements one by one) elements.Therefore, for the first array element, the differences are −5 - 2 = 3 7 - 2 = 5 8 - 2 = 6 9 - 2 = 7Therefore, the subarray for the first element should ... Read More

JavaScript in filter an associative array with another array

Shriansh Kumar
Updated on 11-Sep-2024 10:59:11

1K+ Views

In this problem statement, our task is to write a JavaScript program by which we can simply filter an associative array with the help of another array. Before discussing the solution for the given problem, let's familiarize ourselves with associative array first. What is an associative array? An associative array is a data structure which is used to store the key and value pairs. In this each key is associated with a value given to the key. The keys in this array are unique identifiers that can be used to retrieve their respective values. In an associative array the keys ... Read More

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

Nikitasha Shrivastava
Updated on 18-May-2023 10:46:42

4K+ 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. So for doing this task 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 by which we can add a unique id to every item in the given JSON object. For updating every JSON object by adding new id to every object we will use basic Javascript functionality. For example we ... Read More

Sorting odd and even elements separately JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 15:56:32

973 Views

In our problem statement we have to sort odd and even elements separately with the help of Javascript functionalities. So for doing this task we will use for loops and bubble sort for sorting odd and even numbers separately. Understanding the problem statement The problem statement is to write a Javascript function that will help to sort odd and even numbers in a given array. For example if we have an array [2, 3, 5, 4] then we will first sort even indexed elements [3, 4] and then sort the odd indexed elements in the array [2, 5]. After sorting ... Read More

Random whole number between two integers JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 15:33:53

237 Views

In the given problem statement, we have to find the whole number between two integers with the help of Javascript functionalities. So for doing this task we can use some in-built functions of javascript and also for loop to get the required result. Understanding the problem statement The problem statement is to write a function in Javascript that will help to find out the whole random number between two integer numbers. For example if we want to print a random number between 1 to 5 so there are 5 possibilities, the number can be 1, 2, 3, 4, 5. So ... Read More

Algorithm to get the combinations of all items in array JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 10:49:18

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. So for doing this task we can use a recursive approach that iteratively adds items to a running list of combinations. Understanding the problem statement The problem statement is to write a function in Javascript that will help to find out the combinations of all the elements in an array and create a separate array to show these combinations. For example, if we have an array [ 1, 2 ] so the combinations of this array will ... Read More

Advertisements