Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Front End Technology Articles
Page 371 of 652
The Linked List Class in Javascript
Here is the complete implementation of the LinkedList class in JavaScript. This data structure allows you to store elements in a linear sequence where each element points to the next one. Complete LinkedList Implementation class LinkedList { constructor() { this.head = null; this.length = 0; } insert(data, position = this.length) { let node = new this.Node(data); if (this.head === null) ...
Read MoreArray of multiples - JavaScript
We are required to write a JavaScript function that takes in two numbers, say m and n, and it returns an array of first n multiples of m. For example − If the numbers are 4 and 6 Then the output should be − const output = [4, 8, 12, 16, 20, 24] Example Following is the code − const num1 = 4; const num2 = 6; const multiples = (num1, num2) => { const res = []; for(let i = num1; i ...
Read MoreRemoving Elements from a Double Linked List using Javascript
Removing an element from a doubly linked list involves updating the pointers of adjacent nodes to bypass the node being removed. There are three main cases to consider based on the position of the element. Three Cases for Removal Removing from head: Update head to point to the second node and remove the previous link from the new head node. Removing from tail: Update tail to point to the second-to-last node and set its next pointer to null. Removing from middle: Connect the previous and next nodes directly, bypassing the current node by updating their pointers. ...
Read MoreThe Doubly Linked List class in Javascript
A doubly linked list is a data structure where each node contains references to both the next and previous nodes, allowing bidirectional traversal. Here's a complete implementation of a DoublyLinkedList class in JavaScript. Complete Implementation class DoublyLinkedList { constructor() { this.head = null; this.tail = null; this.length = 0; } insert(data, position = this.length) { let node = new this.Node(data); ...
Read MoreConcatenating variable number of arrays into one - JavaScript
We are required to write a JavaScript function that takes in any number of JavaScript arrays and returns one single array with all the values from input arrays concatenated into it. For example − If the input arrays are − [1, 5], [44, 67, 3], [2, 5], [7], [4], [3, 7], [6] Then the output should be − const output = [1, 5, 44, 67, 3, 2, 5, 7, 4, 3, 7, 6]; Using reduce() and concat() The most straightforward approach uses the reduce() method combined with concat() to merge ...
Read MoreCircular linked lists in Javascript
A Circular Linked List is a variation of the standard linked list where the first element points to the last element and the last element points back to the first element, forming a circle. Both singly and doubly linked lists can be implemented as circular structures. Data: 10 Data: 20 Data: 30 ...
Read MoreSet Data Structure in Javascript
A Set is a built-in data structure in JavaScript that stores unique values of any type. Unlike arrays, Sets automatically prevent duplicate values and don't maintain insertion order for iteration purposes, making them ideal for storing collections of unique items. Creating a Set You can create a Set using the Set constructor: // Empty Set let emptySet = new Set(); console.log(emptySet); // Set with initial values let numbers = new Set([1, 2, 3, 4, 5]); console.log(numbers); // Set automatically removes duplicates let duplicates = new Set([1, 2, 2, 3, 3, 4]); console.log(duplicates); ...
Read MoreFinding special array - JavaScript
An array is a special array if: - All the elements at odd indices are odd - All the elements at even indices are even We need to write a JavaScript function that takes an array and checks if it's a special array or not. Understanding the Logic For an array to be special: Index 0 (even): element must be even Index 1 (odd): element must be odd Index 2 (even): element must be even Index 3 (odd): element must be odd The key insight is that arr[i] % 2 should ...
Read MoreWhen should you use sets in Javascript?
Sets in JavaScript are ideal when you need to store unique elements where order doesn't matter and you primarily need to check for membership of different objects. Sets are also useful when you want to perform operations like union, intersection, and difference similar to mathematical sets. Let's explore both the built-in ES6 Set and understand when to use it effectively. When to Use Sets Use Sets when you need: Unique values only − Automatically prevents duplicates Fast membership testing − O(1) lookup time with has() Set operations − Union, intersection, difference between collections Simple deduplication ...
Read MoreProduct of two number using HOC - JavaScript
Higher Order Functions (HOC) in JavaScript are functions that either receive another function as an argument or return a function as their result. When combined with closures, HOCs become a powerful tool for creating reusable and modular code. In this example, we'll create a Higher Order Function that calculates the product of two numbers using the concept of currying, where a function returns another function. Example Here's how to implement a product calculator using HOC: const num1 = 24; const num2 = 5; const productHOC = num1 => { return ...
Read More