Luhn

in #italast month

//
// This is only a SKELETON file for the 'Luhn' exercise. It's been provided as a
// convenience to get you started writing code faster.
//

export const valid = (candidate) => {
let totalSum = 0;
candidate = candidate.replace(/\s/g, "");
if(candidate.length <=1) return false;
for(let n = candidate.length-1; n>=0; n--){
if(isNaN(candidate[n])) return false;
if(candidate.length % 2 == 0){
if(n % 2 == 0){
let numCandidate = parseInt(candidate[n], 10);
numCandidate *= 2;
if(numCandidate >9) numCandidate -=9;
totalSum += numCandidate;
}
else{
let numCandidatetwo = parseInt(candidate[n], 10);
totalSum += numCandidatetwo;
}
}
else{
if(n % 2 != 0){
let numCandidate = parseInt(candidate[n], 10);
numCandidate *= 2;
if(numCandidate >9) numCandidate -=9;
totalSum += numCandidate;
}
else{
let numCandidatetwo = parseInt(candidate[n], 10);
totalSum += numCandidatetwo;
}
}
}
return totalSum % 10 == 0;
};

Sort:  

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)

The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 62860.75
ETH 3112.64
USDT 1.00
SBD 3.86