moy-fp
Version:
A functional programming library.
33 lines (30 loc) • 669 B
JavaScript
import curry from '../Function/curry'
import toString from '../String/toString'
/**
* [a] -> [a] -> [a]
*/
const intersection = curry(
(list2, list1) => {
const intersectionObj = {},
delimiter = String.fromCharCode(0),
result = []
for(let item of list2){
intersectionObj[
Object.prototype.toString.call(item) +
delimiter +
toString(item)
] = true
}
for(let item of list1){
if(intersectionObj[
Object.prototype.toString.call(item) +
delimiter +
toString(item)
]){
result.push(item)
}
}
return result
}
)
export default intersection