Found 6683 Articles for Javascript

JavaScript in filter an associative array with another array

Nikitasha Shrivastava
Updated on 18-May-2023 14:42:52

718 Views

In this problem statement, our task is to filter an associative array with another array with the help of Javascript. So for doing this task we will use the filter method and includes the Javascript method. 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 do not have numeric indexes. The ... Read More

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

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

3K+ 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

703 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

154 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

3K+ 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

Nth element of the Fibonacci series JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 15:28:18

918 Views

In this problem statement, our aim is to find the nth element in the fibonacci series with the help of Javascript functionalities. To solve this problem we will use a recursive technique. Understanding the problem statement The problem is to write a function in Javascript that will help find the nth number in the fibonacci sequence. For example, if we want to know the 3rd number in the fibonacci series then the 3rd number is 2. What is the Fibonacci series? The Fibonacci sequence is the chain of numbers in which each number is the sum of previous numbers. The ... Read More

Using merge sort to recursive sort an array JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 16:11:38

2K+ Views

In this problem statement, our aim is to sort an array recursively using merge sort and implement the code with the help of Javascript. So below we will discuss Merge sort and its implementation. Understanding the problem statement The problem statement is to write a function for merge sort in Javascript that will help to sort the given input array into an ascending or descending order. And we have to create a function which will sort the elements recursively. What is the recursive sorting technique? Recursion is a technique in which a function calls itself to solve a problem. When ... Read More

Using Sieve of Eratosthenes to find primes JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 16:13:04

1K+ Views

In this problem statement, our aim is to apply a sieve of eratosthenes algorithm to find out the prime numbers with the help of Javascript functionalities. So in our program we will implement a function to find primes numbers up to a given limit. Understanding the problem statement The problem statement is to write a function in Javascript that will work for finding the prime numbers up to a given number. And for implementing this function we will use the Sieve of Eratosthenes algorithm. What is the Sieve of Eratosthenes Algorithm ? The Sieve of Eratosthenes is an easy and ... Read More

Spiraling the elements of a square matrix JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 16:04:33

220 Views

In this problem statement, our main aim is to spiral the elements of the square matrix with the help of Javascript functionalities. There are several methods that can be used to do this task in Javascript. Understanding the problem statement The problem statement is to write a function in Javascript that will show the output as spiraling the elements of a square matrix. For example, if we have a two dimensional matrix as [1, 2] [3, 4], if we spiral the elements in clockwise direction then the output array will be [1, 2, 4, 3]. Logic for the ... Read More

Encrypting a string JavaScript

Nikitasha Shrivastava
Updated on 18-May-2023 12:10:08

3K+ Views

In this problem statement, our task is to encrypt the input plain text in ciphertext with the help of Javascript functionalities. There are several methods that can be used to encrypt a message in Javascript. One simple method to encrypt the string is Caesar Cipher. Understanding the problem statement The problem statement is to write a function in Javascript that will help to encrypt the given input string into a non readable format. For example, if we have a string "hello world", the encrypted version of this string is "khoor zruog" by shifting each character by two positions. What is ... Read More

Advertisements