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 updateUserNameSaveToDb(user, newName, db) { | |
user.name = newName.charAt(0).toUpperCase() + newName.slice(1).toLowerCase(); | |
db.save(user); | |
$('.user-greet').html(`Hello ${user.name}`); | |
} |
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
// https://jsbin.com/guhumaq/4/edit?html,js,console | |
// -- Helpers ------------------- // | |
const reduce = (fn, arr) => arr.reduce(fn, 0) | |
const add = (x, y) => x + y; | |
// -- Sum Func ------------------ // |
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
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); |
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 Student { | |
constructor (student) { | |
this.student = student; | |
} | |
map(f) { | |
const student = Object.assign({}, this.student); | |
return new Student(f(student)) | |
} | |
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
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" |
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
const wrap = (student) => ({ | |
take: (item) => { | |
student.items.push(item); | |
return wrap(student); | |
}, | |
giveHomework: (homeworkQuantity) => { | |
student.homeworkQuantity += homeworkQuantity; | |
return wrap(student); | |
}, | |
doHomework: () => { |
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
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'); |
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
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; |
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
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]; |
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
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 |