loading...

re: Daily Challenge #50 - Number Neighbor VIEW POST

FULL DISCUSSION
 

Here goes some ugly code!

f=a=>{p=parseInt,l=(''+a).length,i=0,r=[a];while(i<l){r.push(...[('0'+(p(a)-(10**i))).slice(-l),''+(p(a)+(10**i))]);++i}return r}

It works like that:

  • Take the input's length
  • Add and subtract 10n (where n goes from 0 to the input's length - 1) to the input number
  • Add a trailing 0 if necessary
  • Return the built array!
f('5555555555').join('\n');
"5555555555
5555555554
5555555556
5555555545
5555555565
5555555455
5555555655
5555554555
5555556555
5555545555
5555565555
5555455555
5555655555
5554555555
5556555555
5545555555
5565555555
5455555555
5655555555
4555555555
6555555555"
code of conduct - report abuse