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
export default function App() { | |
const useFormInput = initialValue => { | |
const [value, setValue] = useState(initialValue); | |
const handleChange = event => setValue(event.target.value); | |
return { value: value, onChange: handleChange }; | |
}; | |
const name = useFormInput(''); | |
const password = useFormInput(''); |
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
// CLASSES | |
class Dog { | |
constructor() { | |
this.sound = 'woof'; | |
} | |
talk() { | |
console.log(this.sound); | |
} | |
} |
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
// Global | |
const numbers = [1, 2, 3, 4, 5, 6] | |
const number = (n) => { | |
return numbers[n] | |
} | |
console.log(number(4)) |
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
Object.equals = (x, y) => { | |
if (x === y) return true; | |
if (!(x instanceof Object) || !(y instanceof Object)) return false; | |
if (x.constructor !== y.constructor) return false; | |
for (let p in x) { | |
if (!x.hasOwnProperty(p)) continue; | |
if (!y.hasOwnProperty(p)) return false; | |
if (x[p] === y[p]) continue; | |
if (typeof x[p] !== 'object') return false; |
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
/** | |
|-------------------------------------------------- | |
| CLASSES | |
|-------------------------------------------------- | |
*/ | |
class Point { | |
constructor(x, y) { | |
this.x = x; | |
this.y = y; |
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
var _ = {}; | |
/*********IDENTITY**********/ | |
_.identity = function(val) { | |
return val; | |
}; | |
/*********FIRST**********/ | |
_.first = function(array, n) { |
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
Mark Williams | waffle iron | 80 | 2 | |
---|---|---|---|---|
Mark Williams | blender | 200 | 1 | |
Mark Williams | knife | 10 | 4 | |
Nikita Smith | waffle iron | 80 | 1 | |
Nikita Smith | knife | 10 | 2 | |
Nikita Smith | pot | 20 | 3 |
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
function LinkedList() { | |
this.head = null; | |
} | |
LinkedList.prototype.isEmpty = function() { | |
return this.head === null; | |
}; | |
LinkedList.prototype.size = function() { | |
var current = this.head; |
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
// Basic Recursion | |
const countDownFrom = (num) => { | |
if (num === 0) return | |
console.log(num) | |
countDownFrom(num - 1) | |
} | |
countDownFrom(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
function reverseString(str) { | |
return str.split('').reverse().join('') | |
} | |
console.log(reverseString('Hello')) | |
// Recursion | |
function reverseString(str) { | |
return (str === '') ? '' : reverseString(str.substr(1)) + str.charAt(0); |
NewerOlder