JavaScript Program to find Number Combination
You are Here:
Find Number Combination
In the following example, we will find all possible combinations of numbers with 4 and 8 within the limit 500.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<h1>Find 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>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.