Articles on Trending Technologies

Technical articles with clear explanations and examples

Subtract two Sets in Javascript

Samual Sam
Samual Sam
Updated on 15-Jun-2020 3K+ Views

The difference of 2 sets means the set being subtracted should have all its elements removed from the set it is being subtracted from. So we can iterate over the second set and remove all the elements present in it from the first set. Examplestatic difference(s1, s2) {    if (!s1 instanceof MySet || !s2 instanceof MySet) {       console.log("The given objects are not of type MySet");       return null;    }    let newSet = new MySet();    s1.forEach(elem => newSet.add(elem));    s2.forEach(elem => newSet.delete(elem));    return newSet; }You can test this using − Exampleconst testSet1 = ...

Read More

The Set Class in Javascript

Samual Sam
Samual Sam
Updated on 15-Jun-2020 176 Views

Here is the complete implementation of the MySet class. Exampleclass MySet {    constructor() {       this.container = {};    }    display() {       console.log(this.container);    }    has(val) {       return this.container.hasOwnProperty(val);    }    add(val) {       if (!this.has(val)) {          this.container[val] = val;          return true;       }       return false;    }    delete(val) {       if (this.has(val)) {          delete this.container[val];          return true;       }   ...

Read More

Remove elements from a linked list using Javascript

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

Removing an element is very easy in a linked list. We just need to get rid of the node we want to remove, ie, lose its reference. There are 3 cases we need to consider −Removing an element from head: In this case, we can simply assign head = head.next. This way we'll lose the reference of the first element. And out head will start pointing to the second element. Removing an element from the tail: In this case, we can simply assign the node.next of second last node to be null and we'll get rid of the last element from ...

Read More

The Linked List Class in Javascript

Samual Sam
Samual Sam
Updated on 15-Jun-2020 201 Views

Here is the complete implementation of the LinkedList class −  Exampleclass LinkedList {    constructor() {       this.head = null;       this.length = 0;    }    insert(data, position = this.length) {       let node = new this.Node(data);       if (this.head === null) {          this.head = node;          this.length++;          return this.head;       }       let iter = 1;       let currNode = this.head;       while (currNode.next != null && iter < position) { ...

Read More

Removing Elements from a Double Linked List using Javascript

Samual Sam
Samual Sam
Updated on 15-Jun-2020 622 Views

Removing an element is very easy in a linked list. We just need to get rid of the node we want to remove, ie, lose its reference. There are 3 cases we need to consider −Removing an element from head: In this case, we can simply assign head = head.next and remove the previous link from the next element. This way we'll lose the reference of the first element. And out head will start pointing to the second element.Removing an element from the tail: In this case, we can simply assign the node.next of second last node to be null ...

Read More

The Doubly Linked List class in Javascript

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

Here is the complete implementation of the DoublyLinkedList Class −Exampleclass DoublyLinkedList {    constructor() {       this.head = null;       this.tail = null;       this.length = 0;    }    insert(data, position = this.length) {       let node = new this.Node(data);       // List is currently empty       if (this.head === null) {          this.head = node;          this.tail = node;          this.length++;          return this.head;       }       // Insertion at ...

Read More

Circular linked lists in Javascript

Samual Sam
Samual Sam
Updated on 15-Jun-2020 565 Views

Circular Linked List is a variation of the Linked list in which the first element points to the last element and the last element points to the first element. Both Singly Linked List and Doubly Linked List can be made into a circular linked list.

Read More

How to append an element after an element using jQuery?

David Meador
David Meador
Updated on 15-Jun-2020 3K+ Views

To append an element after an element using jQuery, use the insertAfter() method.ExampleYou can try to run the following code to learn how to append an element after an element using jQuery:Live Demo           The jQuery Example                              $(document).ready(function() {             $("div").click(function () {                $("#source").insertAfter(this);             });          });                              .div {             margin:10px;             padding:12px;             border:2px solid #666;             width:60px;          }                             Click on any square below to see the result:                                            

Read More

Remove elements from a PriorityQueue using Javascript

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

Dequeuing elements from a PriorityQueue means removing the element of the highest priority. We are storing the elements with the highest priority at the end of the array, we can simply pop it to dequeue it.Hence, we can implement the dequeue function as follows − Exampledequeue() {    // Check if empty    if (this.isEmpty()) {       console.log("Queue Underflow!");       return;    }    return this.container.pop(); }You can check if this function is working fine usinglet q = new PriorityQueue(4); q.enqueue("Hello", 3); q.enqueue("World", 2); q.enqueue("Foo", 8); console.log(q.dequeue()); q.display();OutputThis will give the output −{ data: 'Foo', priority: 8 ...

Read More

How to manipulate CSS pseudo-elements ::before and ::after using jQuery?

David Meador
David Meador
Updated on 15-Jun-2020 3K+ Views

To manipulate CSS pseudo elements using the hover() function. You can try to run the following code to learn how to manipulate CSS pseudo-elements −ExampleLive Demo $(document).ready(function(){     $('span').hover(function(){     $(this).addClass('change').attr('data-content','bar'); }); }); span.change:after {     content: attr(data-content) ' This is demo text.'; } Place cursor below... foo

Read More
Showing 45841–45850 of 61,248 articles
Advertisements