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 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 |
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
| // 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) |
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 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 |
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 ProfitCalculator { | |
| constructor(prices) { | |
| this.prices = prices | |
| } | |
| // implementation 1 uses standard for-loop | |
| getMaxProfit() { | |
| let maxProfit = 0 | |
| let minPrice = this.prices[0] |
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 Tree { | |
| constructor(value, children = []) { | |
| this.value = value | |
| this.children = children | |
| } | |
| isLeaf() { |
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 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 |
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
| 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" | |
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 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) -> # ... |
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
| // 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" }, |
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
| // 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, |