Skip to content

Instantly share code, notes, and snippets.

View SakoMe's full-sized avatar
😎

Sarkis M SakoMe

😎
  • Venice Beach, Ca
View GitHub Profile
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('');
// CLASSES
class Dog {
constructor() {
this.sound = 'woof';
}
talk() {
console.log(this.sound);
}
}
@SakoMe
SakoMe / closure.js
Created January 16, 2018 00:00
Closures...
// Global
const numbers = [1, 2, 3, 4, 5, 6]
const number = (n) => {
return numbers[n]
}
console.log(number(4))
@SakoMe
SakoMe / deepCompare.js
Created January 14, 2018 00:15
helper to compare objects...
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;
@SakoMe
SakoMe / class_vs_proto_vs_functional.js
Created January 4, 2018 20:34
Classes vs Prototype vs Functional Approach
/**
|--------------------------------------------------
| CLASSES
|--------------------------------------------------
*/
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
@SakoMe
SakoMe / underscore.js
Created September 22, 2017 22:21
Basic implementation of underscore.js most commonly used methods
var _ = {};
/*********IDENTITY**********/
_.identity = function(val) {
return val;
};
/*********FIRST**********/
_.first = function(array, n) {
@SakoMe
SakoMe / data.csv
Last active February 21, 2018 01:03
Use of advanced reduce method
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
@SakoMe
SakoMe / linked-list.js
Created September 21, 2017 06:11
Linked list
function LinkedList() {
this.head = null;
}
LinkedList.prototype.isEmpty = function() {
return this.head === null;
};
LinkedList.prototype.size = function() {
var current = this.head;
@SakoMe
SakoMe / recursion.js
Created September 21, 2017 05:27
Taking an array of objects and representing as a tree using recursion
// Basic Recursion
const countDownFrom = (num) => {
if (num === 0) return
console.log(num)
countDownFrom(num - 1)
}
countDownFrom(10)
@SakoMe
SakoMe / reverse_string.js
Created September 20, 2017 20:13
Reverse a string
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);