UNPKG

moy-fp

Version:
32 lines (29 loc) 699 B
import curry from '../Function/curry' import toString from '../String/toString' /** * [a] -> [a] -> [a] */ const union = curry( (list2, list1) => { const unionObj = {}, delimiter = String.fromCharCode(0), result = [] let id for(let item of list1){ id = Object.prototype.toString.call(item) + delimiter + toString(item) if(!unionObj[id]){ result.push(item) unionObj[id] = true } } for(let item of list2){ id = Object.prototype.toString.call(item) + delimiter + toString(item) if(!unionObj[id]){ result.push(item) unionObj[id] = true } } return result } ) export default union