This file contains 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
/** | |
* divorce takes an array of nested array pairs and returns 2 one-dimensional arrays with elements from each pair, in order | |
* ex: divorce([[1,2], [3,4]]) --> {a1: [1,3], a2: [2,4]} | |
*/ | |
const divorce = (arr, a1 = [], a2 = []) => | |
!arr[0] | |
? { a1, a2 } | |
: divorce(arr.slice(1), a1.concat(arr[0][0]), a2.concat(arr[0][1])) |
This file contains 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
// Write a fn `getLength` that takes one argument, an array, and returns the length of that array. | |
// getLength should be written without using the built-in .length() method, and without any `for` or `while` loops. | |
const getLength = ([first, ...rest], len = 0) => | |
!first | |
? len | |
: getLength(rest, len + 1) | |
// ES5 |
This file contains 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
[user] name = jafow | |
email = jared.a.fowler@gmail.com | |
[credential] | |
helper = cache | |
help = cache --timeout 1800 | |
[core] | |
autocrlf = input | |
safecrlf = true | |
editor = vim |
This file contains 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 presidentialPollingData = [{"pollster":"RCP Average","date":"6/27","clinton":45,"trump":39}, | |
{"pollster":"Quinnipiac","date":"6/27","clinton":42,"trump":40},{"pollster":"ABC News/Wash Post","date":"6/23","clinton":51,"trump":39}, | |
{"pollster":"NBC News/Wall St. Jrnl","date":"6/23","clinton":46,"trump":41},{"pollster":"Rasmussen Reports","date":"6/21","clinton":44,"trump":39}, | |
{"pollster":"Reuters/Ipsos","date":"6/22","clinton":44,"trump":34},{"pollster":"Economist/YouGov","date":"6/20","clinton":43,"trump":39}, | |
{"pollster":"CNN/ORC","date":"6/19","clinton":47,"trump":42},{"pollster":"Gravis","date":"6/16","clinton":51,"trump":49}, | |
{"pollster":"Monmouth","date":"6/19","clinton":49,"trump":41},{"pollster":"Rasmussen Reports","date":"6/15","clinton":44,"trump":39}, | |
{"pollster":"Reuters/Ipsos","date":"6/15","clinton":41,"trump":32},{"pollster":"CNBC","date":"6/13","clinton":40,"trump":35}, | |
{"pollster":"Bloomberg*","date":"6/13","clinton":49,"trump":37},{"pollster":"CBS News","date":"6/13","clinton":43,"trump": |
This file contains 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 Row extends Component { | |
// this component receives props and extends it with color and effect. `super()` keyword permits us to use `this` | |
constructor(props) { | |
super(props) | |
this.color = 'blue' | |
this.effect = 'wow' | |
} | |
render () { | |
return ( |
This file contains 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
/** Write a function `combo` that takes two parameters--fn1, fn2--and returns a function. | |
* combo should combine the two function parameters and invoke them on any values passed as arguments | |
* ex: | |
* var add2 = (n) => n + 2; | |
* var times3 = (n) => n * 3; | |
* var plus2AndMultiply3 = combo(add2, times/3) | |
* plus2AndMulitply3(5) // --> 17 | |
*/ | |
// Function composition in Es6 | |
const combo = (fn1, fn2) => (...args) => fn1(fn2(args)); |
This file contains 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
// define a function 'targetSum' that takes 2 arguments, an array and a target number, and returns a boolean for whether or not | |
//2 values in the array sum up to the target number | |
// ex: targetSum([1, 3, 5, 0, 6, 4, 2], 11) // => 11 | |
// brute force | |
function targetSum (arr, target) { | |
for (var i = 0; i < arr.length; i++) { | |
for (var j = i + 1; j < arr.length; j++) { | |
if (arr[i] + arr[j] === target) return true | |
} |
This file contains 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
/** | |
* Write a function mergeRanges that takes an array of meeting time ranges and# | |
* | |
* Example: | |
* var times = [[0, 1], [3, 5], [4, 8], [10, 12], [9, 10] | |
* | |
* mergeRanges(times); -> [[0, 1], [3, 8], [9, 12]] | |
* | |
* Do not assume the ranges are in order | |
*/ |
This file contains 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 rockPaperScissors(num) { | |
var res = [] | |
var t = ['rock', 'paper', 'scissors'] | |
if (num < 1) return [] | |
function rps (part, n) { | |
part = part || [] | |
if (part.length === n) return res.push(part) | |
for (let i = 0, len = t.length; i < len; i++) { |
This file contains 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
require('lookup-multicast-dns/global') | |
const net = require('net') | |
const jsonStream = require('duplex-json-stream') | |
const host = process.argv[3] | |
const nick = process.argv[2] || 'guest' | |
var socket = net.connect(9494, `${host}.local`) | |
socket = jsonStream(socket) |