Front End Technology Articles

Page 530 of 652

What is a block statement in JavaScript?

Nikitha N
Nikitha N
Updated on 15-Jun-2020 997 Views

A block statement groups zero or more statements. In languages other than JavaScript, it is known as a compound statement.SyntaxHere’s the syntax −{    //List of statements }Variables with a block get scoped to the containing function. Block statement never introduce scope and using var to declare variables don’t have block scope.var a = 20; {    var b = 40; }Now, when you will print the value of a, it will print 40, not 20. This is because variable declared with a var within the block has the same scope like var before the block.var a = 20; {    var a = 40; } // this prints 40 document.write(a);

Read More

Complete Graph Class in Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Jun-2020 284 Views

Functions which have been commented out in this code. You can switch to those as well. We've also moved the Queue, Stack, and PriorityQueue classes in different modules that can be imported using either import statements or using require calls. Here is the complete implementation of the Graph class − Exampleconst Queue = require("./Queue"); const Stack = require("./Stack"); const PriorityQueue = require("./PriorityQueue"); class Graph {    constructor() {       this.edges = {};       this.nodes = [];    }    addNode(node) {       this.nodes.push(node);       this.edges[node] = [];    }   ...

Read More

Why to use canvas tag in HTML5?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Jun-2020 300 Views

Specifies height of the canvas.The HTML tag is used to draw graphics, animations, etc. using scripting. The tag introduced in HTML5.Let’s see a simple element with two specific attributes width and height along with all the core HTML5 attributes like id, name, and class etc.Here are the attributes −AttributeValueDescriptionheight pixelsSpecifies height of the canvas.width pixelsSpecifies width of the canvas.ExampleYou can try to run the following code to learn how to use canvas to create a rectangle. The canvas element has a DOM method called getContext, which obtains rendering context and its drawing functions. This function takes one ...

Read More

Calculating the balance factor in a Javascript AVL Tree

karthikeya Boyini
karthikeya Boyini
Updated on 15-Jun-2020 847 Views

AVL tree checks the height of the left and the right sub-trees and assures that the difference is not more than 1. This difference is called the Balance Factor.For example, in the following trees, the first tree is balanced and the next two trees are not balanced −In the second tree, the left subtree of C has height 2 and the right subtree has height 0, so the difference is 2. In the third tree, the right subtree of A has height 2 and the left is missing, so it is 0, and the difference is 2 again. AVL tree ...

Read More

AVL Rotations in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Jun-2020 469 Views

To balance itself, an AVL tree may perform the following four kinds of rotations −Left rotationRight rotationLeft-Right rotationRight-Left rotationThe first two rotations are single rotations and the next two rotations are double rotations. To have an unbalanced tree, we at least need a tree of height 2. With this simple tree, let's understand them one by one.Left RotationIf a tree becomes unbalanced, when a node is inserted into the right subtree of the right subtree, then we perform a single left rotation −In our example, node A has become unbalanced as a node is inserted in the right subtree of ...

Read More

Inserting a node in a Javascript AVL Tree

karthikeya Boyini
karthikeya Boyini
Updated on 15-Jun-2020 287 Views

We can learn how we can insert a node in an AVL Tree. Insertions in AVL trees are the same as BST, we just need to perform one extra step called balance tree during insert whenever we move down the tree.This requires calculating the balance factor which we already saw before. And according to the configurations, we need to call appropriate rotation methods. These are pretty intuitive with the help of the above explanation.We again create a class method and a helper function for recursive calls − Exampleinsert(data) {    let node = new this.Node(data);    // Check if the tree ...

Read More

AVL Tree class in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Jun-2020 846 Views

Here is the complete implementation of the AVL Tree Class −Exampleclass AVLTree {    constructor() {       // Initialize a root element to null.       this.root = null;    }    getBalanceFactor(root) {       return this.getHeight(root.left) - this.getHeight(root.right);    }    getHeight(root) {       let height = 0;       if (root === null || typeof root == "undefined") {          height = -1;       } else {          height = Math.max(this.getHeight(root.left), this.getHeight(root.right)) + 1;       }     ...

Read More

How to create a valid HTML document with no <html><body> and <head> element?

Amit Sharma
Amit Sharma
Updated on 15-Jun-2020 457 Views

With HTML, the essentials are doctype declaration, and . But, you will be amazed to know that a valid HTML document can work without the and element. The doctype declaration will come always since it tells and instructs the browser about what the page is about.Let’s see an example; here we won’t use the html> and element. Still, the HTML Document is valid and will work correctly like any other valid HTML Document − Title of the page This is heading 1 This is heading 2 This is a paragraph.

Read More

How to draw a circular gradient in HTML5?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Jun-2020 323 Views

This method returns a CanvasGradient object that represents a radial gradient that paints along the cone given by the circles represented by the arguments. The first three arguments define a circle with coordinates (x1, y1) and radius r1 and the second a circle with coordinates (x2, y2) and radius r2.createRadialGradient(x0, y0, r0, x1, y1, r1)Here are the parameter values of the createRadialGradient() method −S.NoParameter & Description1x0x-coordinate- Starting point of the gradient2y0y- coordinate - Starting point of the gradient3r0Radius of the starting circle4x1x-coordinate - Ending point of the gradient5y1y- coordinate - Ending point of the gradient6r1Radius of the ending circleYou can ...

Read More

Creating a Graph in Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Jun-2020 1K+ Views

We'll be creating a graph class that supports weights and both directed and undirected types. This will be implemented using an adjacency list. As we move to more advanced concepts, both weights and directed nature of the graphs will come in handy.An adjacency list is an array A of separate lists. Each element of the array Ai is a list, which contains all the vertices that are adjacent to vertex i. We're defining it using 2 members, nodes and edges.Let's set up the graph class by defining our class and some methods that we'll use to add nodes and edges ...

Read More
Showing 5291–5300 of 6,517 articles
« Prev 1 528 529 530 531 532 652 Next »
Advertisements