Display number between 1 to 100 sum of digits 9 ascending order Javascript

By | August 11, 2022

Here is the Javascript program which display the numbers between 1 to 100. It should include the following conditions, The sum of the digits should be 9 and digits and the digits should be in ascending order.

Example : 

36 => 3+6=9 and 3 is less than 6.

We have implemented this code using Javascript.

Javascript Code:

var array = Array.from(Array(100).keys())
array.forEach((val) =>{
constmyArray = val?.toString().split(“”);
let num = myArray.map(Number)
if(num?.length ==2 || num?.length ==3){
let num2=0;
num.forEach(val2 => {
num2+= val2;
})
if (num2 == 9){
constmyArray = val?.toString().split(“”);
let num = myArray.map (Number)
if(num[0]<num[1]){
console.log(val)
}
}
}
})
Output:
18
27
36
45