Advertisement
roronoa

sum chiffres * first

Nov 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //sum chiffres * first
  2. const s = readline();
  3. if(s.replace(/^-/,'').replace(/[0-9]*/,'').length != 0) {
  4.     print('INVALID')
  5.     return
  6. }
  7. let first = s[0] != '-' ? s[0] : s[1]*-1
  8. let n = s.replace(/^-/,'').replace(/^./,'')
  9. print(n.split('').reduce((a,b)=>a+b*1,0)*first)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement