Skip to content

Instantly share code, notes, and snippets.

class IntWithPow(val i: Int) {
def pow(n: Int) = Math.pow(i, n).toInt
}
implicit def intToInt(i: Int) = new IntWithPow(i)
// z = ax + by + c
type LinSolution = (Int, Int, Int)
val testRange = 0 to 5
// assumes the passed-in array contains a single non-duplicate. Finds the non-duplicate.
// O(3n) = O(n) runtime
findNonduplicate = (numbers) => {
const count = {}
// N
numbers.forEach(n => count[n] = count[n] ? count[n] + 1 : 1)
return (Object
.keys(count)
const returnedDrones = {}
function dispatchDrones(drones) {
drones.forEach(d => {
droneId = d.dispatch() // droneId contains a random but unique id
returnedDrones[droneId] = false
}
}
// run this function at end of day
class ProfitCalculator {
constructor(prices) {
this.prices = prices
}
// implementation 1 uses standard for-loop
getMaxProfit() {
let maxProfit = 0
let minPrice = this.prices[0]
@albertywu
albertywu / tree.js
Last active January 19, 2017 02:33
class Tree {
constructor(value, children = []) {
this.value = value
this.children = children
}
isLeaf() {
class Rational(x: Int, y: Int) {
// private method
private def gcd(x: Int, y: Int): Int = if (y == 0) x else gcd(y, x % y)
// private value
private val g = gcd(x, y)
// accessor methods
def numer = x / g // normalize using gcd
sniffer = require('twitter-sniffer')({ # TODO: implement module
consumer_key: '...', # TODO: add key
consumer_secret: '...', # TODO: add key
access_token: '...', # TODO: add key
access_token_secret: '...' # TODO: add key
})
SNIFF_PHRASE = "Live on #Periscope"
class Peribot
constructor: (robot) ->
@cache = null
@robot = robot
@robot.brain.on 'loaded', => # ... set up @cache
@listen() # sets up robot listeners
add: (user_or_hashtag) -> # ...
remove: (user_or_hashtag) -> # ...
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "shift+cmd+-", "command": "workbench.action.openPreviousEditor" },
{ "key": "shift+cmd+=", "command": "workbench.action.openPreviousEditor" },
{ "key": "shift+cmd+-", "command": "workbench.action.quickOpenNavigatePrevious",
"when": "inQuickOpen" },
{ "key": "shift+cmd+=", "command": "workbench.action.quickOpenNavigateNext",
"when": "inQuickOpen" },
{ "key": "shift+cmd+[", "command": "editor.foldLevel2",
"when": "editorFocus" },
// Place your settings in this file to overwrite the default settings
{
"filePicker.alternateFileNameMatching": true,
"editor.fontLigatures": true,
"editor.fontFamily": "Fira Code",
"editor.fontSize": 15,
"editor.lineHeight": 22,
"editor.tabSize": 2,
"editor.wrappingColumn": -1,
"editor.formatOnType": true,