Skip to content

Instantly share code, notes, and snippets.

View minmaxdata's full-sized avatar
🐕

Ke McAdams minmaxdata

🐕
  • 17:53 (UTC -07:00)
View GitHub Profile
@minmaxdata
minmaxdata / async-await.js
Created August 4, 2018 22:52 — forked from iHani/async-await.js
async await basic example.
const isLargerOrEqualTo100 = (a) => {
return new Promise((resolve, reject) => {
if (a >= 100) {
resolve(`${a} is >= 100`)
} else {
reject(`${a} is < 100`)
}
})
}
@minmaxdata
minmaxdata / Currying.js
Created August 4, 2018 22:52 — forked from iHani/Currying.js
Currying (also partial application)
function person (name) {
return function age (age) {
return `${name} is ${age}`
}
}
// if we called
const arg1 = 'Richard'
const arg2 = 30
console.log(person(arg1)(arg2))
@minmaxdata
minmaxdata / helper.js
Created August 4, 2018 22:42
Helper Functions
for (const day of days) {
console.log(day.charAt(0).toUpperCase().trim().concat(day.slice(1)));
}
@minmaxdata
minmaxdata / reducer.js
Created August 4, 2018 22:41
Reducer Example
/* Create A Reducer
*
* You need to create a reducer called "appReducer" that accepts two arguments:
* - First, an array containing information about ice cream
* - Second, an object with a 'DELETE_FLAVOR' `type` key
* (i.e., the object contains information to delete the flavor from the state)
*
* The action your reducer will receive will look like this:
* { type: 'DELETE_FLAVOR', flavor: 'Vanilla' }
*
@minmaxdata
minmaxdata / arraysort.js
Created August 4, 2018 22:33
Array sort
myList.sort(function(x, y){
return x.timestamp - y.timestamp;
})
@minmaxdata
minmaxdata / hash.js
Created August 4, 2018 22:30
Javascript Hash
var twoSum = function(nums, target) {
const hash = {};
for (let i = 0; i < nums.length; i++) {
const comp = target - nums[i];
if (hash[comp] !== undefined) {
return [hash[comp], i];
}
@minmaxdata
minmaxdata / ternary.js
Created August 4, 2018 22:28
Ternary examples
this.setState((state)=> (
showInput: !state.showInput
))
{showInput && (
<View …>
)
}
@minmaxdata
minmaxdata / awaitasync.js
Created August 4, 2018 22:24
Await Async Example
loadFlashCards = async () => {
const value = await AsyncStorage.getItem('flashcards');
if (value !== null){
this.setState({
flashcards: JSON.parse(value)
});
}
}
@minmaxdata
minmaxdata / arraymap.js
Last active August 4, 2018 22:37
An example using array .map()
{questions.map((question, index) => (
<Card
key={index}
question={question.question}
answer={question.answer}
index={index}
/>
))}
{Object.keys(decks).map(key => {
@minmaxdata
minmaxdata / alert.js
Created August 4, 2018 22:19
ReactAlertExample
onPressHandle() {
Alert.alert(
'Alert Title',
'My Alert Msg',
[
{
text: 'Ask me later',
onPress: () => console.log('Ask me later pressed')
},