Functional Implementation of the Luhn Algorithm. No variable declaration, No mutation. A simple, lightweight implementation using composition. Used for testing a credit cards checksum value. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from mistyped or otherwise incorrect numbers.
The goal was to write a LUHN Algorithm using a functional programming paradigm. A series of composable lambas that are processed right to left. Not a single if / else statement. All branching is handled by ternary functions with implicit returns.
Yarn:
yarn add fp-luhnNPM:
npm i fp-luhnAccepts a numeric string. Eg: '4111111111111111'
import luhn from 'fp-luhn'
luhn('4916737743057301') // true