fork download
  1. #!/usr/bin/env js91
  2.  
  3. "use strict";
  4.  
  5. // 余再帰
  6. function unfold(p, f, g, seed, tail_gen = (x) => []) {
  7. const acc = tail_gen(seed)
  8. while (!(p(seed))) {
  9. acc.push(f(seed));
  10. seed = g(seed);
  11. }
  12. return acc;
  13. }
  14.  
  15. function Func(num, max) {
  16. return unfold(
  17. (x) => x * (x % 10) > max,
  18. (x) => x,
  19. (x) => x + 1,
  20. num).at(-1) % 10;
  21. }
  22.  
  23. function main(args) {
  24. if (args.length) {
  25. console.log(`N = ${Func(...args.map((x) => parseInt(x)))}`);
  26. } else {
  27. console.log("wrong number of arguments");
  28. }
  29. }
  30.  
  31. main(scriptArgs);
Success #stdin #stdout 0.03s 16756KB
stdin
Standard input is empty
stdout
wrong number of arguments