I'm facing an issue with my JavaScript code that seems to be causing it not to run properly.
<p id="demo"></p>
Here is the JS code:
function isSubsetSum(arr, n, sum) {
if (sum == 0) {
return true;
}
if (n == 0 && sum != 0) {
return false;
}
if (arr[n - 1] > sum) {
return isSubsetSum(arr, n - 1, sum);
}
return isSubsetSum(arr, n - 1, sum) || isSubsetSum(arr, n - 1, sum - arr[n - 1]);
}
function findPartiion(arr, n) {
var sum = 0;
for (int i = 0; i < n; i++) {
sum += arr[i];
}
if (sum % 2 != 0) {
return false;
}
return isSubsetSum(arr, n, sum / 2);
}
var arr = {3,1,1,2,2,1};
var n = fruits.length;
if (findPartiion(arr, n) == true) {
document.getElementById("demo").innerHTML = "Can be divided into two subsets of equal sum";
} else {
document.getElementById("demo").innerHTML = "Cannot be divided into two subsets of equal sum";
}
Despite adding the HTML code as shown above, I am unable to get any output from my JavaScript. When I execute the code, nothing appears on the screen. Thank you for your assistance in this matter.