Skip to content

Instantly share code, notes, and snippets.

@Buggytheclown
Last active January 28, 2020 12:23
Show Gist options
  • Save Buggytheclown/258db3dbeb3a365c310e7241a227188d to your computer and use it in GitHub Desktop.
Save Buggytheclown/258db3dbeb3a365c310e7241a227188d to your computer and use it in GitHub Desktop.
Some good tasks for JS developers
/*
* Descriptions:
* Implement curry function.
*/
// Outputs:
function sum3(a, b, c){
return a + b + c;
}
var sum3_curryed = curry(sum3);
sum3_curryed(1)(2)(3) // or sum3_curryed(1, 2)(3) of sum3_curryed(1)(2, 3)
// -> 6
/*
* Descriptions:
* Implement myBind method without using bind, call, apply.
*/
// Outputs:
function getThis(){
return this;
}
var a = 'Bind me';
getThis.myBind(a);
getThis();
// -> 'Bind me'
/*
* Descriptions:
* Return true;
*/
function count(f) {
return f() === 1
&& f()() === 2
&& f()()() === 3
&& f()()()() === 4
&& f()()()()() === 5
}
/*
* Descriptions:
* Implement sum function.
*/
// Outputs:
sum(1)(2)() // -> 3
sum(0)(2)(3)(5)() // -> 10
/*
* Descriptions:
* Implement myNew function.
*/
class Person {
constructor(name) {
this.name = name;
}
getName() {
return this.name;
}
}
const person = myNew(Person, "Vasia");
person.getName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment