Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function count_digits(d, n) {
- let count = 0;
- for (let index = 0; index <= n; index++) {
- const a = index.toString();
- if (d == a) {
- count++;
- }
- if (a.length > 1) {
- var b = a.split('');
- for (let index = 0; index < b.length; index++) {
- const element = b[index];
- if (d == element) {
- count++;
- }
- }
- }
- }
- return count;
- }
- console.log(count_digits(2, 34));
Add Comment
Please, Sign In to add comment