Can't you just return the value? Or am I missing something?
var InRow = function(cell, row) {
cell = 1;
if (contains(row, cell)) {
cell = 2;
if (contains(row, cell)) {
cell = 3;
if (contains(row, cell)) {
cell = 4;
if (contains(row, cell)) {
return false;
} else {
cell = 4;
}
} else {
cell = 3;
}
} else {
cell = 2;
}
} else {
cell = 1;
}
return cell;
}
And then :
var cell = InRow(A4, ROW1);
console.log(cell);
Also what is the point of passing in A4
into the function and then overwriting it with a value of 1? You can rewrite the whole thing to this and it will have the same effect.
var InRow = function(row) {
var cell = 1;
if (contains(row, cell)) {
cell = 2;
if (contains(row, cell)) {
cell = 3;
if (contains(row, cell)) {
cell = 4;
if (contains(row, cell)) {
return false;
} else {
cell = 4;
}
} else {
cell = 3;
}
} else {
cell = 2;
}
} else {
cell = 1;
}
return cell;
}
var cell = InRow(ROW1);
console.log(cell);