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
const get = prop => obj => obj[prop]; | |
array.map(get('key')); | |
const match = req => obj => Object.keys(req).every(key => Object.keys(obj).includes(key) && obj[key] === req[key]); | |
array.filter(match({'key': value})); |
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
(new Date(2016, 7, 17).getTime() - new Date(2016, 2, 17).getTime()) / 1000 / 3600 / 24 |
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 fish_greeting | |
echo ' '(set_color F00)'___ | |
___======____='(set_color FF7F00)'-'(set_color FF0)'-'(set_color FF7F00)'-='(set_color F00)') | |
/T \_'(set_color FF0)'--='(set_color FF7F00)'=='(set_color F00)') '(set_color red)(whoami)'@'(hostname)' | |
[ \ '(set_color FF7F00)'('(set_color FF0)'0'(set_color FF7F00)') '(set_color F00)'\~ \_'(set_color FF0)'-='(set_color FF7F00)'='(set_color F00)')'(set_color yellow)' Uptime:'(set_color white)(uptime | sed 's/.*up \([^,]*\), .*/\1/')(set_color red)' | |
\ / )J'(set_color FF7F00)'~~ \\'(set_color FF0)'-='(set_color F00)') Theme: '(set_color white)(echo $fish_theme)(set_color red)' | |
\\\\___/ )JJ'(set_color FF7F00)'~'(set_color FF0)'~~ '(set_color F00)'\) '(set_color yellow)'Version: '(set_color white)(echo $FISH_VERSION)(set_color red)' | |
\_____/JJJ'(set_color FF7F00)'~~'(set_color FF0)'~~ '(set_color F00)'\\ | |
'(set_color FF7F00)'/ '(set_color FF0)'\ '(set_color FF0)', \\'(set_color F00)'J'(set_color |
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 mapValues(obj, fn) { | |
return Object.keys(obj).reduce((result, key) => { | |
result[key] = fn(obj[key], key); | |
return result; | |
}, {}); | |
} | |
function pick(obj, fn) { | |
return Object.keys(obj).reduce((result, key) => { | |
if (fn(obj[key])) { |
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
((f, t, p) => { | |
/** | |
* Returns cat's face | |
*/ | |
const face = (type) => { | |
switch (type) { | |
case 0: | |
return '( x .x)'; | |
case 1: | |
return '( o .o)'; |
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
averages = n => n ? n.reduce((x,y,i,z) => i < z.length - 1 ? x.concat((y + z[i + 1] || 0) / 2) : x, []) : []; |
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
{ shouldFlag: selectedIds => this.messages.filter(m => selectedIds.includes(m.id)).some(m => !m.flagged) } |
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
{ | |
shouldFlag: function(selectedIds) { | |
// Assume don't flag | |
var shouldFlagMessages = false; | |
// Keep track of how many are flagged and not flagged | |
var flaggedCount = 0; | |
var unFlaggedCount = 0; | |
// Get only the messages we care about | |
var messagesInQuestion = []; |
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
const addNumers = (a, b) => a + b; | |
// Takes the values of an array and returns the total. Demonstrates simple | |
// recursion. | |
const totalForArray = (arr, currentTotal) => { | |
currentTotal = addNumers(currentTotal + arr.shift()); | |
if (arr.length) { | |
return totalForArray(currentTotal, arr); | |
} else { |
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
const A = ["d", "a", "c", "b"]; | |
const I = [3, 0, 2, 1]; | |
A.reduce((x, y, i, arr) => x.concat(arr[I.indexOf(i)]), []); | |
// > ["a", "b", "c", "d"] | |
// Functional Programming Power! | |
const sortExternalFromArray = z => (x, y, i, arr) => x.concat(arr[z.indexOf(i)]); | |
// A more elegant/reusable approach | |
A.reduce(sortExternalFromArray(I), []); |