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
/** | |
* Converts Arabic numeric chars to English. | |
* @param {Number} number - The Arabic number to be converted to English number. | |
* Thanks to whomever I stole this code from on the web a while ago. | |
* Michael Scott: It's whoever, not whomever. | |
* Ryan: It's whomever. | |
* Michael Scott: No, whomever is never acutally right. | |
* Jim Halpert: Nope, sometimes it's right. | |
* Creed: Michael is right. It's a made up word used to trick students- | |
*/ |
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
/* | |
* Array.reducer() | |
* "The reduce() method executes a reducer function (that you provide) on each | |
* element of the array, resulting in a single output value" - MDN Docs | |
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce | |
*/ | |
const arr = [1, 10, 4]; | |
// get the sum of all elements in the array |
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
// "The map() method creates a new array with the results of calling a provided function on every element in the calling array." - MDN | |
// .map() returns an array of the same length, don't use it for filtering, use .filter() insted | |
/* example 1 */ | |
const fruits = [ 'orange', 'apple', 'pineapple' ]; | |
// maps are good for 'applying' something on every element in the array, let's apply .toUpperCase() | |
const fruitsUppercase = fruits.map(fruit => fruit.toUpperCase()); | |
console.log(fruitsUppercase); | |
// [ 'ORANGE', 'APPLE', 'PINEAPPLE' ] |
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 person (name) { | |
return function age (age) { | |
return `${name} is ${age}` | |
} | |
} | |
// if we called | |
const arg1 = 'Richard' | |
const arg2 = 30 | |
console.log(person(arg1)(arg2)) |
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 isLargerOrEqualTo100 = (a) => { | |
return new Promise((resolve, reject) => { | |
if (a >= 100) { | |
resolve(`${a} is >= 100`) | |
} else { | |
reject(`${a} is < 100`) | |
} | |
}) | |
} |
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
// Higher Order Component (HOC) : A component that renders another component | |
// Goal: Reduce code, render hijacking, prop manipulation, abstract state | |
// Inspired by mead.io videos on Udemy | |
import React from 'react' | |
import reactDOM from 'react-dom' | |
const info = (props) => ( | |
<div> | |
<h1>Hello { props.isAdmin ? 'admin' : 'guest' }</h1> |
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
/* | |
* Array spread operator | |
*/ | |
const arr = [1, 3, 5] | |
arr.concat(7) | |
// [1, 3, 5, 7] // returns a new array, doesn't change arr | |
arr.push(11) | |
// [1, 3, 5, 11] // actually changes arr |
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
/* | |
* Object Destructuring | |
*/ | |
const book = { | |
title: 'ReWork', | |
author: 'Some guy', | |
publisher: { | |
name: 'Penguin' | |
} | |
} |
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
# coding: utf-8 | |
import oauth2 as oauth | |
import json | |
CONSUMER_KEY = "yT577ApRtZw51q4NPMPPOQ" | |
CONSUMER_SECRET = "3neq3XqN5fO3obqwZoajavGFCUrC42ZfbrLXy5sCv8" | |
ACCESS_KEY = "" | |
ACCESS_SECRET = "" | |
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET) |
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
/* | |
* ** 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) => { |
NewerOlder