Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. const peselValidation = (pesel: number) => {
  2. const peselString = pesel.toFixed()
  3. const weights = [9, 7, 3, 1, 9, 7, 3, 1, 9, 7];
  4. let sum = 0;
  5.  
  6. for (let index = 0; index < weights.length; index++) {
  7. sum += parseInt(peselString.substring(index, index + 1), 10) * weights[index];
  8. }
  9.  
  10. sum = sum % 10;
  11. const response = (sum === parseInt(peselString.substring(10, 11), 10));
  12.  
  13. return response;
  14. }
  15.  
  16. const peselDate = (pesel: number) => {
  17. const peselString = pesel.toFixed()
  18. let year: number = parseInt(peselString.substring(0, 2)),
  19. month: number | string = parseInt(peselString.substring(2, 4), 10) - 1,
  20. day: number = parseInt(peselString.substring(4, 6), 10)
  21.  
  22. const monthString = [
  23. 'stycznia',
  24. 'lutego',
  25. 'marca',
  26. 'kwietnia',
  27. 'maja',
  28. 'czerwca',
  29. 'lipca',
  30. 'sierpnia',
  31. 'września',
  32. 'października',
  33. 'listopada',
  34. 'grudnia'
  35. ];
  36.  
  37. if (year > 80) {
  38. year = year + 1800
  39. month = month - 80
  40. } else if (month > 60) {
  41. year = year + 2200
  42. month = month - 60
  43. } else if (month > 40) {
  44. year = year + 2100
  45. month = month - 40
  46. } else if (month > 20) {
  47. year = year + 2200
  48. month = month - 80
  49. } else {
  50. year = year + 1900
  51. }
  52.  
  53. return `${day} ${monthString[month - 1]} ${year}`;
  54. }
  55.  
  56. console.log(peselValidation(73072255843));
  57. console.log(peselDate(73072255843));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement