Yeah, it’s a little ugly. If you properly indent, it’s a little better. And I like to label close brackets if they’re far from their open, like this:
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
var answer = [];
arr = arr.concat(collection);
var matchKeys = Object.keys(source);
var matchValues = Object.values(source);
for (i=0; i<arr.length; i++) {
var truth = 0;
for (j=0; j<Object.keys(arr[i]).length; j++) {
for (k=0; k<matchValues.length; k++) {
if (Object.keys(arr[i])[j] == matchKeys[k]) {
truth += 1;
if (truth == matchValues.length) {
if (Object.values(arr[i])[j] == matchValues[k]) {
answer.push(arr[i]);
}
} // if (truth...
} // if (Object.keys...
} // for k
} // for j
} // for i
// Only change code above this line
return answer;
}
I’ve also been labelling closing brackets. I find the whole brackets thing to be the most annoying thing about programming so far. Labelled brackets help immensely by saving you a lot of time.