UNPKG

bingo-functional-js

Version:

A port of the PHP bingo-functional library

28 lines (23 loc) 506 B
const sizeOf = require('./sizeOf') /** * keyExists function * * keyExists :: [a, b] -> String -> Bool * @param {(array|object)} haystack * @param {string} needle * @returns {boolean} * @example * * keyExists(['foo', 'bar', 'baz'], '2') * // => true */ const keyExists = (haystack, needle) => { const result = [] for (const [key, value] of Object.entries(haystack)) { if (needle === key) { result.push(value) } } return sizeOf(result) !== 0 } module.exports = keyExists