This file contains hidden or 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 createQueue() { | |
| const queue = []; | |
| return { | |
| enqueue(item) { | |
| queue.unshift(item) | |
| }, | |
| dequeue() { | |
| return queue.pop() | |
| }, |
This file contains hidden or 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
| import { createQueue } from './index'; | |
| function createPriorityQueue() { | |
| const lowPriorityQueue = createQueue(); | |
| const highPriorityQueue = createQueue(); | |
| return { | |
| enqueue(item, isHighPriority = false) { | |
| isHighPriority | |
| ? highPriorityQueue.enqueue(item) |
This file contains hidden or 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 createStack() { | |
| const stack = [] | |
| return { | |
| push(item) { | |
| stack.push(item) | |
| }, | |
| pop() { | |
| return stack.pop() | |
| }, |
This file contains hidden or 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 createNode(value) { | |
| return { | |
| value, | |
| next: null | |
| } | |
| } | |
| function createLinkedList() { | |
| return { | |
| head: null, |
This file contains hidden or 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
| const { createQueue } = require('../queues/index.js') | |
| function createNode(key) { | |
| const children = [] | |
| return { | |
| key, | |
| children, | |
| addChild(node) { | |
| children.push(node) |
This file contains hidden or 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 createNode(key) { | |
| const children = [] | |
| return { | |
| key, | |
| children, | |
| addChild(childKey) { | |
| const childNode = createNode(childKey) | |
| children.push(childNode) | |
| return childNode |
This file contains hidden or 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 createBinaryNode(key) { | |
| return { | |
| key, | |
| left: null, | |
| right: null, | |
| addLeft(leftKey) { | |
| const newLeft = createBinaryNode(leftKey) | |
| this.left = newLeft | |
| return newLeft | |
| }, |
This file contains hidden or 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
| // global scope | |
| var name = 'Damian'; | |
| function getName() { | |
| console.log(name); // 'Damian' | |
| } |
This file contains hidden or 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
| // global scope | |
| var name = 'Damian'; | |
| function getName(name) { // passing (name) makes it local scope | |
| console.log(a); // log the given argument, not the global value of '1' | |
| } | |
| // local scope again | |
| function localScope() { | |
| var isGlobalScope = false; |
This file contains hidden or 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 canIVote = 'No'; | |
| function areYouOlderThan18() { | |
| if (true) { | |
| var canIVote = 'Yes'; | |
| } | |
| console.log(canIVote); // log 'Yes', not the global value of 'No' | |
| } |
OlderNewer