HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>JS Number Combination</h1> <script> var combination = 2; var num = [4,8]; var limit = 500; var i, j, lastDigit, copyNum, flag, count; //Iterate from 1 to limit for(i=1; i <= limit; i++) { copyNum = i; count = 0; flag = 0; //Check each digit starting from last digit while(copyNum != 0) { count++; lastDigit = copyNum % 10; for(j = 0; j < combination; j++) { if(num[j] == lastDigit) flag++; } copyNum = Math.floor(copyNum / 10); } //result if(count == flag) document.write(i +" "); } </script> <p><strong>Note</strong>: In this example, we are finding all possible combination of numbers with 4 and 8 within the limit 500.</p> </body> </html>
OUTPUT
×

Save as Private