Skip to content

Instantly share code, notes, and snippets.

View daronwolff's full-sized avatar
🏠
Working from home

daronwolff daronwolff

🏠
Working from home
  • Me
  • México
View GitHub Profile
@daronwolff
daronwolff / exercise_3.js
Created May 20, 2016 19:34
Write a function that takes an argument and returns a function that returns that argumen
"use strict";
function identify(x) {
return function(){
return x;
}
}
var idf = identify(3);
idf(); // 3
@daronwolff
daronwolff / factorial.js
Created May 20, 2016 16:41
Javascript Factorial function
function factorial(n) {
"use strict";
var result = 1;
while (n > 1) {
result *= n;
console.log(result);
n -= 1;
}
}
@daronwolff
daronwolff / exercise_2.js
Last active May 20, 2016 19:29
Write two binary functions "add" and "mul", that take two numbers and return their sum and product
"use strict";
var add = (function(a){
return function (b){
return a + b;
}
});
var mul = (function(a){
return function(b){
var total = a * b;
return total;
@daronwolff
daronwolff / isArray.js
Created May 19, 2016 23:05
This little script is used to test if an array is really an array or not.
"use strict";
if (Array.prototype.isArray === undefined) {
Array.prototype.isArray = function (value) {
return Object.prototype.toString.apply(value) === "[object Array]";
};
}
/*
Examples
*/
Array.isArray({}); //false
@daronwolff
daronwolff / array_inverter.js
Last active May 19, 2016 18:10
Javascript - Invert array position elements manually. I created this little code to my friends in Kwan
"use strict";
if (!Array.prototype.reverseOrder) {
Array.prototype.invertir = function() {
var inverted = [];
for (var i = this.length - 1; i >= 0; i--) {
inverted[this.length - (i + 1)] = this[i];
}
return inverted;
}
}