Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
11
test/luhnCheck/luhnCheck.js
Normal file
11
test/luhnCheck/luhnCheck.js
Normal file
@ -0,0 +1,11 @@
|
||||
const luhnCheck = num => {
|
||||
let arr = (num + '')
|
||||
.split('')
|
||||
.reverse()
|
||||
.map(x => parseInt(x));
|
||||
let lastDigit = arr.splice(0, 1)[0];
|
||||
let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + (val * 2) % 9 || 9), 0);
|
||||
sum += lastDigit;
|
||||
return sum % 10 === 0;
|
||||
};
|
||||
module.exports = luhnCheck;
|
||||
Reference in New Issue
Block a user