daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(){
  2.     function createCheckDigit(membershipId) {
  3.         var arrString,tambahArr,hasilArrTambah;
  4.      
  5.         //pisahkan string (jika lebih dari dua digit) ke dalam array integer
  6.         arrString=membershipId.split('').map(function(item){
  7.             return parseInt(item,10);
  8.         });
  9.        
  10.         //menambah seluruh value di dalam array dengan reduce
  11.         tambahArr=function(a,b){
  12.             return a+b;
  13.         }
  14.  
  15.     hasilArrTambah=arrString.reduce(tambahArr);
  16.        
  17.         //return hasilnya, jika masih dua digit, rekursif fungsi createCheckDigit, jika sudah satu digit, langsung return
  18.         return (hasilArrTambah > 9) ? createCheckDigit(hasilArrTambah.toString()) : hasilArrTambah.toString();
  19.     }
  20.     console.log(createCheckDigit("55555"));
  21. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top