Day 94: Spell Each Digit Using Recursion of 100DaysCodingChallenge
Hello all,
#day94
Day94
Today's my task was to Write a Program to Spell each Digit Separately an input Number n and then have to spell each digit separately. (n is entered by user) using Recursion.Today's my task was to Write a Program to Spell each Digit Separately an input Number n and then have to spell each digit separately. (n is entered by user) using Recursion.
I have started the 100 days of coding challenge to improve my programming skills..
Code :
function spell_num(number) { if (number < 10) // base case. { console.log(number, ""); } else { spell_num(Math.floor(number / 10)); // recursive call. console.log(number % 10, ""); } } //spell_num(567); let n = parseInt(prompt("Enter a Number : ")); spell_num(n); const reduce = (fn, acc, [cur, rest]) => cur === undefined ? acc : reduce(fn, fn(acc, cur), rest); //console.log(reduce((a, b) => a + b, 0, [1, 2, 3, 4, 5, 6, 7, 8, 9])); // 45
Output :
Happy Coding:)
Thank you...
Comments
Post a Comment