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
class Animal { | |
constructor(name, energy) { | |
this.name = name | |
this.energy = energy | |
} | |
eat(amount) { | |
console.log(`${this.name} is eating.`) | |
this.energy += amount | |
} |
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
class Animal { | |
constructor(name, energy) { | |
this.name = name | |
this.energy = energy | |
} | |
eat(amount) { | |
console.log(`${this.name} is eating.`) | |
this.energy += amount | |
} |
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 anagram(first, second) { | |
let one = [...first]; | |
let two = [...second]; | |
let temp = {} | |
const len = one.length === two.length; | |
if (len) { | |
temp = one.reduce(function (letters, letter) { | |
if (letter in letters) { | |
letters[letter]++ |
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 hasDuplicates(numbers) { | |
let memo = {}; | |
let count = 0; | |
numbers.map(number => { | |
if (!memo[number]) { | |
memo[number] = 1; | |
} else { | |
count++; | |
} |
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
/* | |
* 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
// 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
/* | |
* forEach | |
*/ | |
// forEach is very simlar to for-looping arr.length | |
// array.forEach(callback, context) | |
var arr = ['apple', 'orange', 'watermelon', 10, 20, 30] | |
arr.forEach((value, index) => console.log(`Element's ${index} type is ${typeof value}`)) | |
// Prints: | |
// Element 0 type is string |
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
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` |
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) => { |