Guest User

Untitled

a guest
Feb 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. function count_digits(d, n) {
  2. let count = 0;
  3. for (let index = 0; index <= n; index++) {
  4. const a = index.toString();
  5.  
  6.  
  7. if (d == a) {
  8. count++;
  9. }
  10. if (a.length > 1) {
  11. var b = a.split('');
  12.  
  13. for (let index = 0; index < b.length; index++) {
  14. const element = b[index];
  15. if (d == element) {
  16. count++;
  17. }
  18. }
  19. }
  20. }
  21.  
  22. return count;
  23. }
  24. console.log(count_digits(2, 34));
Add Comment
Please, Sign In to add comment