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 existsSum(arr, n, lIndex = 0, hIndex = null, iter = 0) { | |
const low = arr[lIndex]; | |
const high = arr[hIndex || arr.length - 1]; | |
const predicate = low + high; | |
if (iter === arr.length - 1) return false; | |
if (predicate === n) { | |
return true; | |
} | |
if (predicate < n) { | |
// increment lower index |
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
// Wrap an async function so we catch any errors that might occur | |
const wrapAsync = handler => (req, res) => | |
handler(req, res) | |
.then(result => res.json(result)) | |
.catch(error => res.status(500).json({ error: error.message })) |
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 t = (function () { | |
var _listeners = {}; | |
/** | |
* Compare with a new listener handler | |
* to make sure we are not adding the same handler | |
* @param String EventType | |
* @param Function Callback | |
* @returns Boolean true if exists false if not | |
*/ | |
var _existsHandler = function (eventType, cb) { |
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 existsSum(arr, n, lIndex = 0, hIndex = null, iter = 0) { | |
const low = arr[lIndex]; | |
const high = arr[hIndex || arr.length - 1]; | |
const predicate = low + high; | |
if(iter === arr.length - 1 ) return false; | |
if(predicate === n) return true; | |
if(predicate < n) { | |
// increment lower index | |
return existsSum(arr, n, lIndex + 1, hIndex, iter + 1); | |
} else { |
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 { useReducer } from 'react' | |
export function updateName(name: string) { | |
return <const>{ | |
type: 'UPDATE_NAME', | |
name | |
} | |
} | |
export function addPoints(points: number) { |
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 BinarySearchTree(val) { | |
this.value = val; | |
this.left = null; | |
this.right = null; | |
} | |
BinarySearchTree.prototype.insert = function(value) { | |
let subtree = value < this.value ? 'left' : 'right'; | |
if (this[subtree]) { | |
this[subtree].insert(value); |
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
class LinkList { | |
constructor(value) { | |
this._head = { value, next: null }; | |
this._tail = this._head; | |
} | |
insert(value) { | |
//update tail as needed | |
const node = { value, next: null }; | |
this._tail.next = 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
<!DOCTYPE html> | |
<!-- | |
* | |
* Copyright (C) 2016, bitmovin GmbH, All Rights Reserved | |
* | |
* This source code and its use and distribution, is subject to the terms | |
* and conditions of the applicable license agreement. | |
* | |
--> | |
<html lang="en"> |
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
defmodule GuessingGame do | |
def guess(a, b) when a > b, do: guess(b, a) | |
def guess(low, high) do | |
answer = IO.gets("Maybe you thinking of #{mid(low, high)}? ") | |
case String.trim(answer) do | |
"bigger" -> | |
bigger(low, high) |
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 SBMonitor = [] | |
var sysCallMap = {}; | |
function getDiff(key) { | |
let diff = 0; | |
const now = new Date().getTime(); | |
if(sysCallMap[key]) { | |
diff = now - sysCallMap[key]; | |
} | |
sysCallMap[key] = now; |