Peeking Elements from a PriorityQueue using JavaScript

Samual Sam
Updated on 15-Jun-2020 09:14:15

173 Views

Peeking a PriorityQueue means getting the value with the highest priority without removing it. So we can implement the peek function as follows &minusl Examplepeek() {    if (isEmpty()) {       console.log("Queue Underflow!");       return;    }    return this.container[this.container.length - 1]; }You can check if this function is working fine using − Examplelet q = new PriorityQueue(4); q.enqueue("Hello", 3); q.enqueue("World", 2); q.enqueue("Foo", 8); console.log(q.peek()); q.display();OutputThis will give the output −{ data: 'Foo', priority: 8 } [ { data: 'World', priority: 2 },    { data: 'Hello', priority: 3 },    { data: 'Foo', priority: 8 } ]As ... Read More

Determine if a Variable is Undefined or Null

Swarali Sree
Updated on 15-Jun-2020 09:13:24

904 Views

On getting the result of the following, you can find whether a variable is null or undefined. If the result is “false”, it means the variable is null and undefined.Here, the variable results in “True” −                    var age = 10;          if(age) {             document.write("True");          } else {             document.write("False");          }          

Difference Between ajaxSend and ajaxStart Functions in jQuery

David Meador
Updated on 15-Jun-2020 09:13:18

511 Views

ajaxSend() methodThe ajaxSend(callback) method attaches a function to be executed whenever an AJAX request is sent.Here is the description of all the parameters used by this method:callback − The function to execute. The XMLHttpRequest and settings used for that request are passed as arguments to the callback.Assuming we have the following HTML content in result.html file:THIS IS RESULT...ExampleThe following is an example showing the usage of this method:Live Demo           The jQuery Example                              $(document).ready(function() {           ... Read More

Clear Elements of the PriorityQueue using JavaScript

karthikeya Boyini
Updated on 15-Jun-2020 09:12:27

161 Views

We can clear the contents just by reassigning the container element to an empty array. For example, clear() {    this.container = []; }ExampleYou can check if this function is working fine using − let q = new PriorityQueue(4); q.enqueue("Hello", 3); q.enqueue("World", 2); q.enqueue("Foo", 8); q.display(); q.clear(); q.display();OutputThis will give the output −[ { data: 'World', priority: 2 },   { data: 'Hello', priority: 3 },   { data: 'Foo', priority: 8 } ] [ ]

What Does the cmp Function Do in Python Object-Oriented Programming

Rajendra Dharmkar
Updated on 15-Jun-2020 09:11:48

570 Views

The cmp() functionThe cmp(x, y) function compares the values of two arguments x and y −cmp(x, y)The return value is −A negative number if x is less than y.Zero if x is equal to y.A positive number if x is greater than y.The built-in cmp() function will typically return only the values -1, 0, or 1. However, there are other places that expect functions with the same calling sequence, and those functions may return other values. It is best to observe only the sign of the result.>>> cmp(2, 8) -1 >>> cmp(6, 6) 0 >>> cmp(4, 1) 1 >>> cmp('stackexchange', ... Read More

Difference Between ajaxStop and ajaxComplete Functions in jQuery

David Meador
Updated on 15-Jun-2020 09:11:19

948 Views

ajaxStop() methodThe ajaxStop( callback ) method attaches a function to be executed whenever all AJAX requests have ended.Here is the description of all the parameters used by this method −callback − The function to execute.Assuming we have following HTML content in result.html file:THIS IS RESULT...ExampleThe following is an example showing the usage of this method:Live Demo           jQuery ajaxStop() method                              $(document).ready(function() {                         /* Global variable */       ... Read More

The PriorityQueue Class in JavaScript

Samual Sam
Updated on 15-Jun-2020 09:10:49

247 Views

Here is the complete implementation of the PriorityQueue class −Exampleclass PriorityQueue {    constructor(maxSize) {       // Set default max size if not provided       if (isNaN(maxSize)) {          maxSize = 10;        }       this.maxSize = maxSize;       // Init an array that'll contain the queue values.       this.container = [];    }    // Helper function to display all values while developing    display() {       console.log(this.container);    }    // Checks if queue is empty    isEmpty() {     ... Read More

Difference Between ajaxSuccess and ajaxComplete Functions in jQuery

David Meador
Updated on 15-Jun-2020 09:09:45

408 Views

ajaxSuccess() methodThe ajaxSuccess( callback ) method attaches a function to be executed whenever an AJAX request completes successfully. This is an Ajax Event.Here is the description of all the parameters used by this method −callback − The function to execute. The event object, XMLHttpRequest, and settings used for that request are passed as arguments to the callback.Assuming we have the following HTML content in result.html file:THIS IS RESULT...ExampleThe following is an example showing the usage of this method:Live Demo           The jQuery Example                         ... Read More

Basic Operations Supported by a List in JavaScript

Samual Sam
Updated on 15-Jun-2020 09:08:53

224 Views

Following are the basic operations supported by a list.Insertion − add an element at the beginning of the list.Deletion − delete an element at the beginning of the list.Display − displaying the complete list.Search − search an element using given key.Delete − delete an element using given key.

Difference Between Local Events and Global Events in jQuery

David Meador
Updated on 15-Jun-2020 09:08:05

3K+ Views

Ajax requests produce a number of different events that you can subscribe to. There are two types of events:Local EventsThese are callbacks that you can subscribe to within the Ajax request object.$.ajax({    beforeSend: function(){       // Handle the beforeSend event    },    complete: function(){      // Handle the complete event    }    // ...... });Global EventsThese events are broadcast to all elements in the DOM, triggering any handlers which may be listening. You can listen for these events like so:$("#loading").bind("ajaxSend", function(){    $(this).show();  }).bind("ajaxComplete", function(){    $(this).hide(); });Global events can be disabled, for a ... Read More

Advertisements