Last active
July 12, 2018 08:16
-
-
Save savayer/fc5c450647f4252f527b0992561bcdc7 to your computer and use it in GitHub Desktop.
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
/*http://dkab.github.io/jasmine-tests/*/ | |
/*1*/ | |
function sequence(start=0, step=1) { | |
var tmp = start-step; | |
return function() { | |
return tmp += step; | |
} | |
} | |
/*****************/ | |
function sequence(start, step) { | |
start = start || 0; | |
step = step || 1; | |
var tmp = start-step; | |
return function() { | |
return tmp += step; | |
} | |
} | |
/*************************/ | |
/*2*/ | |
function take(fn, count) { | |
var result = []; | |
for (var i=0; i<count;i++) { | |
result.push(fn()); | |
} | |
return result; | |
} | |
/*3*/ | |
function map(fn, array) { | |
var result = []; | |
for (var i=0; i<array.length;i++) { | |
result.push(fn(array[i])); | |
} | |
return result; | |
} | |
/*************************/ | |
function map(fn, array) { | |
var res = []; | |
[].forEach.call(array, function(array_item) { | |
res.push( fn(array_item) ) | |
}) | |
return res; | |
} | |
/*************************/ | |
/*4*/ | |
function fmap(a, gen) { | |
return function() { | |
return a(gen.apply(this, arguments)); | |
} | |
} | |
function square(x) { | |
return x * x; | |
} | |
function sequence(start=0, step=1) { | |
var tmp = start-step; | |
return function() { | |
return tmp += step; | |
} | |
} | |
/*5*/ | |
function partial(callback, ...bindes) { | |
return function(...args) { | |
return callback(...bindes, ...args); | |
} | |
} | |
/*or*/ | |
function partial(fn) { | |
var arr = [].slice.call(arguments,1); | |
return function() { | |
return fn.apply(this,arr.concat([].slice.call(arguments))) | |
} | |
} | |
/*6*/ | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment