Skip to content

Instantly share code, notes, and snippets.

View saginadir's full-sized avatar
:octocat:

Sagi saginadir

:octocat:
View GitHub Profile
@saginadir
saginadir / my.js
Last active January 13, 2017 11:21
$('.myClass').addClass('bird').show().animate({/* some animation */});
@saginadir
saginadir / my.js
Last active January 13, 2017 11:21
const $myClass = $('.myClass');
$.addClass($myClass, 'bird');
$.show($myClass);
$.animate($myClass, {/* some animation */})
const add = (a, b) => a + b;
console.log(add(3, 4)); // will output 7
add(1, 2) + add(3 + 3); // Add the result of 2 functions together
const toArray = (...args) => args; // turns all args to array.
// [2] position hold 'Apple', allowing us to directly access it after the function.
toArray(1, 'f', 'Apple', {hello: 'world'})[2];
const toArray = (...args) => args; // turns all args to array.
const res1 = toArray(1, 'f', 'Apple', {hello: 'world'})[2].toUpperCase();
console.log(res1); // Will outut APPLE;
const res2 = toArray(1, 'f', 'Apple', {hello: 'world'})[2].toUpperCase().substr(0,3);
console.log(res2); // Will outut APP;
const wrap = (el) => ({
css: (attribute, value) => {
el.style[attribute] = value;
return wrap(el);
},
hide: () => {
return wrap(el).css('display', 'none');
},
show: () => {
return wrap(el).css('display', 'block');
const wrap = (student) => ({
take: (item) => {
student.items.push(item);
return wrap(student);
},
giveHomework: (homeworkQuantity) => {
student.homeworkQuantity += homeworkQuantity;
return wrap(student);
},
doHomework: () => {
const student = newStudent('Josh');
student
.logMyState()
.giveHomework(2)
.doHomework() // "Missing pencil to do homework"
.take('ruler')
.take('coffee')
.logMyState()
.doHomework() // "Missing pencil to do homework"
class Student {
constructor (student) {
this.student = student;
}
map(f) {
const student = Object.assign({}, this.student);
return new Student(f(student))
}
@saginadir
saginadir / gist.js
Last active January 17, 2017 07:52
const pipe = (fn,...fns) => (...args) => !fns.length ? fn(...args) : pipe(...fns)(fn(...args));
const getKittens =
cats => cats.filter(cat => cat.months < 7);
const namesToList =
listOfObjects => listOfObjects.map(ob => ob.name);
const getKittenNames = pipe(getKittens, namesToList);