This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reverseLinkedList(head){ | |
let prev = null; | |
let next = null; | |
while(head){ | |
next = head.next; | |
head.next = prev; | |
prev = head; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numArray.sort((a, d) => a - d); // For ascending sort | |
numArray.sort((a, d) => d - a); // For descending sort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.stdin.resume(); | |
process.stdin.setEncoding("utf-8"); | |
var stdin_input = ""; | |
process.stdin.on("data", function (input) { | |
stdin_input += input; // Reading input from STDIN | |
}); | |
process.stdin.on("end", function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Queue = (()=>{ | |
const map = new WeakMap(); | |
let _items = [] | |
class Queue{ | |
constructor(...items){ | |
//initialize the items in queue | |
map.set(this, []); | |
_items = map.get(this); | |
// enqueuing the items passed to the constructor | |
this.enqueue(...items) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Stack = (()=>{ | |
let map = new WeakMap(); | |
let _items = []; | |
class Stack { | |
constructor(...items){ | |
// let's store our items array inside the weakmap | |
map.set(this, []); | |
// let's get the items array from map, and store it in _items for easy access elsewhere |
NewerOlder