| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 1× 3× 3× 466× 452× | 'use strict'
/**
* A simple and fast memoization function
*
* It helps creating functions that convert from string to pitch in array format.
* Basically it does two things:
* - ensure the function only receives strings
* - memoize the result
*
* @name memoize
* @function
* @private
*/
module.exports = function (fn) {
var cache = {}
return function (str) {
if (typeof str !== 'string') return null
return (str in cache) ? cache[str] : cache[str] = fn(str)
}
}
|