Skip to content

Instantly share code, notes, and snippets.

View SakoMe's full-sized avatar
😎

Sarkis M SakoMe

😎
  • Venice Beach, Ca
View GitHub Profile
@SakoMe
SakoMe / promise-vs-async-await.js
Last active June 14, 2017 01:52
Promises vs async / await...
//SET UP
const users = [{
id: 1,
name: 'Bob',
schoolId: 101
}, {
id: 2,
name: 'Jane',
schoolId: 999
// Functional JS to flatten an array...
const flatten = (array) => {
return array.reduce((flat, toFlatten) => {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
console.log(flatten([[1,2,[3]],4]));
@SakoMe
SakoMe / ES5.js
Created July 5, 2017 01:57
ES5 vs ES6 constructor functions
'use strict';
/**
* Shape class.
*
* @constructor
* @param {String} id - The id.
* @param {Number} x - The x coordinate.
* @param {Number} y - The y coordinate.
*/
@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);
@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 / 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 / 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 / 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 / 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 / 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;