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
Javascript Articles
Page 401 of 534
Complete Graph Class in Javascript
This article presents a comprehensive Graph class implementation in JavaScript with various graph algorithms including traversal, shortest path, and minimum spanning tree algorithms. Graph Class Structure The Graph class uses an adjacency list representation with two main properties: nodes - Array storing all graph vertices edges - Object mapping each node to its connected neighbors with weights Basic Graph Operations const Queue = require("./Queue"); const Stack = require("./Stack"); const PriorityQueue = require("./PriorityQueue"); class Graph { constructor() { this.edges = {}; ...
Read MoreAdding an element in an array using Javascript
Adding an element to an array can be done using different functions for different positions. Adding an element at the end of the array This can be accomplished using the push method. For example, let veggies = ["Onion", "Raddish"]; veggies.push("Cabbage"); console.log(veggies); This will give the output − ["Onion", "Raddish", "Cabbage"] You can also use this to push multiple items at the same time as it supports a variable number of arguments. For example, let veggies = ["Onion", "Raddish"]; veggies.push("Cabbage", "Carrot", "Broccoli"); console.log(veggies); This will give the ...
Read MoreLooping through an array in Javascript
Arrays are linear data structures that store multiple elements in an ordered collection. Each element can be accessed using its index number, starting from 0. const array_name = [item1, item2, ...]; const movies = ["Bahubali", "RRR", "KGF", "Pushpa"]; // Index values: // Bahubali – [0] // RRR – [1] // KGF – [2] // Pushpa – [3] Loops are programming constructs that execute a sequence of instructions repeatedly until a specified condition is met. They're essential for iterating through arrays efficiently. Traditional for Loop The for loop provides complete control over initialization, condition, ...
Read MoreDynamic Programming in JavaScript
Dynamic programming breaks down complex problems into smaller sub-problems and stores their solutions to avoid redundant calculations. This technique is particularly useful for optimization problems where overlapping sub-problems exist. Dynamic programming is used where we have problems that can be divided into similar sub-problems so that their results can be re-used. Before solving a sub-problem, the algorithm checks if it has already been solved and stored. The solutions of sub-problems are combined to achieve the optimal solution. When to Use Dynamic Programming For a problem to benefit from dynamic programming: The ...
Read MoreThe Fibonacci sequence in Javascript
The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. The sequence starts with 1, 1 (or sometimes 0, 1). 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Naive Recursive Approach The most straightforward way to generate the nth Fibonacci number uses recursion: function fibNaive(n) { if (n
Read MoreArrayBuffer.byteLength Property in JavaScript
ArrayBuffer object in JavaScript represents a fixed-length binary data buffer. The byteLength property of the ArrayBuffer returns an unsigned, 32-bit integer that specifies the size/length of the ArrayBuffer in bytes. Syntax arrayBuffer.byteLength Return Value Returns a number representing the length of the ArrayBuffer in bytes. This value is established when the ArrayBuffer is constructed and cannot be changed. Example: Basic Usage JavaScript ArrayBuffer Example var arrayBuffer = new ArrayBuffer(8); ...
Read MoreArrayBuffer.isView() function in JavaScript
The ArrayBuffer.isView() static method determines whether a given value is an ArrayBuffer view. ArrayBuffer views include typed arrays (like Int32Array, Float64Array) and DataView objects. Syntax ArrayBuffer.isView(value) Parameters value: The value to test whether it's an ArrayBuffer view. Return Value Returns true if the value is an ArrayBuffer view (typed array or DataView), false otherwise. Example 1: Testing Typed Arrays ArrayBuffer.isView() Example // Create typed arrays ...
Read MoreArrayBuffer.slice() function in JavaScript
The ArrayBuffer object in JavaScript represents a fixed-length binary data buffer. The slice() method creates a new ArrayBuffer containing a copy of the specified portion of the original buffer. Syntax arrayBuffer.slice(start, end) Parameters start (optional): The byte index where the slice begins (inclusive). Defaults to 0. end (optional): The byte index where the slice ends (exclusive). Defaults to buffer length. Return Value Returns a new ArrayBuffer containing the copied bytes from the specified range. Example: Basic ArrayBuffer Slicing ArrayBuffer Slice Example ...
Read MoreAtomics.xor() function in JavaScript
The Atomic object of JavaScript is an object that provides atomic operations such as add, sub, and, or, xor, load, store etc. as static methods. These methods are used with SharedArrayBuffer objects for thread-safe operations in multi-threaded environments. The xor() function of the Atomics object accepts an array, position, and value, then performs a bitwise XOR operation on the value at the given position atomically. Syntax Atomics.xor(typedArray, index, value) Parameters typedArray - A shared integer typed array (Int8Array, Uint8Array, Int16Array, etc.) index - The position in the array to operate on value ...
Read MoreJSON. stringify( ) function in JavaScript
The JSON.stringify() method converts a JavaScript object or value to a JSON string. This is the reverse of JSON.parse() which converts JSON strings back to JavaScript objects. Syntax JSON.stringify(value, replacer, space) Parameters value: The JavaScript value to convert to JSON string (required) replacer: Function or array to transform values (optional) space: Number of spaces or string for indentation (optional) Basic Example JSON.stringify Example var obj = {Tutorial: "JavaScript", Version: "ES6", ...
Read More