3
I am testing an excerpt of code here in javascript and is giving syntax error on line 12. It says that is missing a ;
somewhere, but I’ve already reviewed that code and I can’t find the error.
This code was originally written in C and I’m trying to adapt to a specific problem using javascript. I changed values defined as integers to var
, I’ve already changed to type char
since javascript is weakly typed and the ==
means that "circumvents" the type differences of the variables.
var arr = ["1", "2", "3", "4", "5"];
var r = "3";
var n = (arr.length)/(arr[0].length);
var data[r];
function combinationUtil(var arr[], var data[], var start, var end, var index, var r)
{
// Current combination is ready to be printed, print it
if (index == r)
{
for (var j=0; j<r; j++){
console.log(data[j]);
//document.getElementById("demo").innerHTML = data[j];
}
}
// replace index with all possible elements. The condition
// "end-i+1 >= r-index" makes sure that including one element
// at index will make a combination with remaining elements
// at remaining positions
for (var i=start; i<=end && end-i+1 >= r-index; i++)
{
data[index] = arr[i];
combinationUtil(arr, data, i+1, end, index+1, r);
}
}
combinationUtil(arr, data, 0, n-1, 0, r);
<p id="demo"></p>
What would that line 12 be?
– user28595
Sorry for the delay in responding. It is the line that indicated below that contains var data[r];
– Jack Jibbers