Please review these string checking functions. This is the whole module
which is actually written here. It supports buffer
, array
, and
string
by checking the char
code.
const charCode = chr => typeof chr === 'number' ? chr : chr.charCodeAt(0)
const every = (fn) => (list) => {
for (let i = 0; i < list.length; ++i)
if (!fn(list[i])) return false
return true
}
const compose = (f, g) => a => f(g(a))
const inBetween = (num, min, max) => num >= min && num <= max
const space = code => code == 9 || code == 10 || code == 12 ||
code == 13 || code == 32
const numeric = code => inBetween(code, 48, 57)
const lowerAlpha = code => inBetween(code, 97, 122)
const upperAlpha = code => inBetween(code, 65, 90)
const alpha = code => lowerAlpha(code) || upperAlpha(code)
const alphaNumeric = code => numeric(code) || alpha(code)
const printable = code => space(code) || inBetween(code, 32, 127)
My thought is is that this style is less readable than the original one. What do you think about its readability? And do these functions satisfy what said as functional?