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
| SELECT | |
| date_trunc('hour', dt) dt, | |
| ((array_agg(bid ORDER BY dt ASC))[1] + | |
| (array_agg(ask ORDER BY dt ASC))[1])/2 o, | |
| (MAX(bid) + MAX(ask))/2 h, | |
| (MIN(bid) + MIN(ask))/2 l, | |
| ((array_agg(bid ORDER BY dt DESC))[1] + | |
| (array_agg(ask ORDER BY dt DESC))[1])/2 c, | |
| SUM(bid_vol) bid_vol, | |
| SUM(ask_vol) ask_vol, |
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
| // Make a message bus object for use in your client-side (in-browser) code. | |
| // The name (label) of a message type should be called the topic, in your code. This is standard pub/sub nomenclature. | |
| // The payload is optional. | |
| // Subscribers must be notified in the exact order that they originally subscribed. | |
| // inside component A... | |
| // messageBus.subscribe('new_signup', function(payload) { | |
| // // do something with the payload | |
| // }); |
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 vowelDoubler = function (array) { | |
| let count = 0; | |
| for (let i = 0; i < array.length; i++) { | |
| if (['a', 'e', 'i', 'o', 'u'].includes(array[i])) { | |
| count++; | |
| } | |
| } | |
| for (let i = array.length - 1, j = i + count; i >= 0; i--, j--) { |
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
| /** | |
| * @param {number[]} nums | |
| * @return {number[]} | |
| */ | |
| var productExceptSelf = function(nums) { | |
| var output = nums.slice().fill(1); | |
| var temp = 1; | |
| for (var i = 0; i < nums.length; i++) { | |
| output[i] = temp; |
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
| // O(n) space complexity solution | |
| var kthSmallest = function(root, k) { | |
| var stack = []; | |
| var count = 0; | |
| var node = root; | |
| while (node) { | |
| stack.push(node); | |
| node = node.left; | |
| } |
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 Tree = function (val) { | |
| this.val = val; | |
| this.children = []; | |
| }; | |
| const hasPathToSum = function(node, targetSum) { | |
| if (node.val === targetSum) { | |
| return true; | |
| } |
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
| // Prompt: tackling floating-point imprecision with the CashAmount class | |
| class CashAmount { | |
| constructor(double) { | |
| this.pennies = parseInt(double * 100, 10); | |
| } | |
| totalInPennies() { | |
| return this.pennies; | |
| } |
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 http = require("http"), | |
| url = require("url"), | |
| path = require("path"), | |
| fs = require("fs") | |
| port = process.argv[2] || 8888; | |
| http.createServer(function(request, response) { | |
| var uri = url.parse(request.url).pathname | |
| , filename = path.join(process.cwd(), uri); |
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 BinaryTree = function (value) { | |
| this.value = value; | |
| this.left = null; | |
| this.right = null; | |
| }; | |
| // Starting Level at root = 0 | |
| const findLargestLevel = function(node) { | |
| var queue = [[node, 0]]; | |
| var levelSum = []; |
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
| /** | |
| * @param {number} numRows | |
| * @return {number[][]} | |
| */ | |
| var generate = function(numRows) { | |
| var result = []; | |
| for (var i = 0; i < numRows; i++) { | |
| var row = []; |
NewerOlder