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
Articles by karthikeya Boyini
Page 37 of 143
Creating a linked list using Javascript
A linked list is a dynamic data structure where elements (nodes) are stored in sequence, with each node containing data and a reference to the next node. Let's build a complete linked list implementation in JavaScript. Basic Structure We'll start by defining a LinkedList class and a Node structure: class LinkedList { constructor() { this.head = null; this.length = 0; } } LinkedList.prototype.Node = class { constructor(data) ...
Read MoreRemove elements from a linked list using Javascript
Removing an element from a linked list involves breaking the connections between nodes. There are three main scenarios to handle based on the position of the element to be removed. Three Cases for Element Removal Removing from head: Simply assign head = head.next to lose reference to the first element. Removing from tail: Set the second-to-last node's next property to null. Removing from middle: Connect the previous node directly to the node after the one being removed: prevNode.next = nodeToRemove.next. Visual Illustration Original List: ...
Read MoreDOMException Failed to load because no supported source was found
The "DOMException Failed to load because no supported source was found" error occurs when media elements (video, audio) cannot load their source files. This is commonly caused by CORS restrictions, incorrect file paths, or unsupported formats. Common Causes This error typically happens due to: Cross-Origin Resource Sharing (CORS) restrictions Incorrect file paths or missing media files Unsupported media formats Server configuration issues Method 1: Setting crossOrigin for CORS When loading media from different domains, set the crossOrigin attribute to handle CORS restrictions: const ...
Read MoreBlending two images with HTML5 canvas
To blend two images using HTML5 canvas, you need to manipulate pixel data from both images and combine them in equal proportions (50-50). This technique uses the canvas getImageData() and putImageData() methods. HTML Structure First, set up the HTML elements with the images and canvas: Blended image: window.onload = function () { var myImg1 = document.getElementById('myImg1'); var myImg2 = document.getElementById('myImg2'); var myCanvas = document.getElementById("canvas"); var ctx = myCanvas.getContext("2d"); // ...
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 MoreHow to draw large font on HTML5 Canvas?
To draw large font text on HTML5 Canvas, you need to set the font size using the font property and use fillText() or strokeText() methods to render the text. Basic Syntax context.font = "size family"; context.fillText(text, x, y); context.strokeText(text, x, y); Example: Drawing Large Text Large Font Canvas var myCanvas = document.getElementById("myCanvas"); var ...
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 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 MoreCreating a Set using Javascript
In JavaScript, a Set is a collection of unique values. You can create sets using the native ES6 Set class or implement a custom set class. Let's explore both approaches. Creating Sets with ES6 Set Class The simplest way to create a set is using the built-in Set constructor: // Create empty set const set1 = new Set(); // Create set with initial values const set2 = new Set([1, 2, 5, 6]); console.log(set1); console.log(set2); Set(0) {} Set(4) { 1, 2, 5, 6 } Custom Set Implementation You can ...
Read MoreHow to set the boldness of the font with JavaScript?
Use the fontWeight property in JavaScript to set the font boldness. This CSS property accepts values like "normal", "bold", "bolder", "lighter", or numeric values from 100 to 900. Syntax element.style.fontWeight = value; Parameters The fontWeight property accepts the following values: Value Description "normal" Default weight (equivalent to 400) "bold" Bold weight (equivalent to 700) "bolder" Bolder than parent element "lighter" Lighter than parent element 100-900 Numeric values (100 = thinnest, 900 = boldest) Example: Setting Font Weight with ...
Read More