Skip to content

Instantly share code, notes, and snippets.

@learningjs
Created January 10, 2016 16:34
Show Gist options
  • Save learningjs/75a75d34e8083705df38 to your computer and use it in GitHub Desktop.
Save learningjs/75a75d34e8083705df38 to your computer and use it in GitHub Desktop.
function map (fn, list) {
var end = list.length
var idx = -1
var out = []
while (++idx < end) {
out.push(fn(list[idx]))
}
return out
}
// math.js
'use strict'
// NOTE: remember to `npm install curry2`
const curry2 = require('curry2')
exports.binaryAdd = curry2(binaryAdd)
/**
* Addition of two integers.
*
* @param {Number} n1
* First integer.
*
* @param {Number} n2
* Second integer.
*
* @return {Number}
* Sum of adding two integers.
*/
function binaryAdd (n1, n2) {
return n1 + n2
}
// math.js
'use strict'
exports.binaryAdd = binaryAdd
/**
* Addition of two integers.
*
* @param {Number} n1
* First integer.
*
* @param {Number} n2
* Second integer.
*
* @return {Number}
* Sum of adding two integers.
*/
function binaryAdd (n1, n2) {
return n1 + n2
}
'use strict'
const add = require('./math').binaryAdd
const integers = [3, 4, 5]
map(add(10), integers)
// => [ 13, 14, 15 ]
'use strict'
const add = require('./math').binaryAdd
const integers = [3, 4, 5]
map(n => add(10, n), integers)
// => [ 13, 14, 15 ]
'use strict'
const add = require('./math').binaryAdd
const add10 = add.bind(null, 10)
const integers = [3, 4, 5]
map(add10, integers)
// => [ 13, 14, 15 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment