Skip to content

Instantly share code, notes, and snippets.

View minmaxdata's full-sized avatar
🐕

Ke McAdams minmaxdata

🐕
  • 10:46 (UTC -07:00)
View GitHub Profile
@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 / ternary.js
Created August 4, 2018 22:28
Ternary examples
this.setState((state)=> (
showInput: !state.showInput
))
{showInput && (
<View …>
)
}
@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 / arraysort.js
Created August 4, 2018 22:33
Array sort
myList.sort(function(x, y){
return x.timestamp - y.timestamp;
})
@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 / 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 / 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 / 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 / Promises.js
Created August 4, 2018 22:58 — forked from iHani/Promises.js
Promises in JavaScript with examples
/*
* ** Diffrence between Tasks and Promises:
* Once settled, a promise can not be resettled. Calling resolve() or reject() again will have no effect. The immutability of a settled promise is an important feature.
* https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-promise-27fc71e77261
* *** First arg is for 'resolved' status, and the second is for 'rejected'
*/
// exampe 1
const myPromise = function () {
return new Promise((Yay, Nay) => {
@minmaxdata
minmaxdata / classes.js
Created August 6, 2018 20:10 — forked from iHani/classes.js
Example of classes in JavaScript ES2015
class Person {
constructor(name = 'Anonymous', age = 0) {
this.name = name
this.age = age
}
getGreeting(){
return `Hi, I am ${this.name}`
}
getDescription(){
return `${this.name} is ${this.age} years old`