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
URL: http://skeeto.s3.amazonaws.com/share/JEOPARDY_QUESTIONS1.json.gz | |
The json file is an unordered list of questions where each question has | |
'category' : the question category, e.g. "HISTORY" | |
'value' : $ value of the question as string, e.g. "$200" | |
Note: This is "None" for Final Jeopardy! and Tiebreaker questions |
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
#!/bin/bash | |
# Variables (feel free to edit these) | |
FROM_CURRENCY='usd' | |
TO_CURRENCY='cad' | |
# Constants | |
USER_AGENT="User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36" | |
SEARCH_URL="https://www.google.com/search?hl=en&q=$FROM_CURRENCY%20to%20$TO_CURRENCY" |
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
/* | |
Naive implementation | |
*/ | |
let everyonesName = ''; | |
users.forEach(user => { | |
everyonesName += `${user.firstName} ${user.lastName}\n`; | |
}); | |
/* | |
Better one-line-using-reduce implementation |
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
// arrayFind accepts an array and returns a function | |
// the returned function accepts the finder function | |
const arrayFind = arr => fn => arr.reduce((acc, item, index) => { | |
// We pass the finder function the item and the index | |
if (fn(item, index)) return item; | |
return acc; | |
}); | |
// Creates a finder function for just our fruits | |
const fruitFinder = arrayFind(fruits); | |
// Now we can pass a finder function to fruitFinder (seen as `fn` above) |
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 thisShitIsBananas = fruits.reduce((accumulator, fruit) => { | |
if (fruit.name === 'bananas') return fruit; | |
return accumulator | |
}); |
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 fruits = [ | |
{ name: ‘apples’, quantity: 2 }, | |
{ name: ‘bananas’, quantity: 0 }, | |
{ name: ‘cherries’, quantity: 5 } | |
]; | |
const thisShitIsBananas = fruits.reduce((accumulator, fruit) => { | |
return accumulator | |
}); |
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 isInTwenties = user => user.age >= 20 && user.age < 30; | |
const makeFullName = user => `${user.firstName} ${user.lastName}`; | |
const isAtLeastTenChars = fullName => fullName.length >= 10; | |
const twentySomethingsLongFullNames = users.reduce( | |
// The first arg that .reduce takes is the reducer function | |
// It has the signature: | |
// - `accumulator` - this is what you build up as you move through the array | |
// - `user` - this is the reference to the item in the array we are currently on | |
// - `index` - not used here, but you can get the index of the current place in the array you are |
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 isInTwenties = user => user.age >= 20 && user.age < 30; | |
const makeFullName = user => `${user.firstName} ${user.lastName}`; | |
const isAtLeastTenChars = fullName => fullName.length >= 10; | |
const twentySomethingsLongFullNames = users.filter(isInTwenties) | |
.map(makeFullName) | |
.filter(isAtLeastTenChars); |
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 twentySomethingsLongFullNames = users | |
// First we filter only the users who are in their twenties | |
.filter(user => user.age >= 20 && user.age < 30) | |
// Combine first and last names | |
.map(user => `${user.firstName} ${user.lastName}`) | |
// Now remove any names that are 9 or less characters | |
.filter(fullName => fullName.length >= 10); |
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 users = [ | |
{ | |
firstName: 'Bob', | |
lastName: 'Doe', | |
age: 37, | |
}, { | |
firstName: 'Rita', | |
lastName: 'Smith', | |
age: 21, | |
}, { |
NewerOlder