Advertisement
nikolayneykov

Untitled

Apr 13th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve ([params]) {
  2.   let result = []
  3.   params
  4.     .split('&')
  5.     .map(x => x.match(/^([A-Za-z\d]{25}|[A-Za-z\d]{16})$/))
  6.     .filter(x => x)
  7.     .forEach(x => {
  8.       result.push(
  9.         x[1]
  10.           .toUpperCase()
  11.           .split('')
  12.           .map(x => (isNaN(x) ? x : 9 - Number(x)))
  13.           .join('')
  14.           .match(x[0].length === 16 ? /.{4}/g : /.{5}/g)
  15.           .join('-')
  16.       )
  17.     })
  18.  
  19.   console.log(result.join(', '))
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement