null category values sometimes not replaced with "Blank"

Issue #639 resolved
David Platten created an issue

The chartUpdateData.js file includes several functions that look for empty strings or null chart category values and replaces them with the word Blank. However, the existing code sometimes fails to work.

Current code:

var index = nameList.indexOf(null || "");
if (index !== -1) {nameList[index] = "Blank";}

For the above code if nameList contains null values, but no empty values then the null values are not replaced with Blank. This seems to be because the || "" part of the indexOf is run after the check for null, and returns -1 as no empty strings were found.

In addition, the above code will only ever find the first instance of the problematic category name. We need to find and replace them all.

I think that the solution is to have an array of things to check for, and loop through each. Something like this should solve both issues above:

var blank_indicators = ["", null];
var i, j;

for (i = 0; i < blank_indicators.length; i++) {
    for (j = 0; j < nameList.length; j++) {
        if (nameList[j] === blank_indicators[i]) {
            nameList[j] = "Blank";
        }
    }
}

Comments (4)

  1. David Platten reporter

    Moved blank checking to a function to reduce duplication. Changed a variable name to camel case. Hopefully these changes will brighten up Codacy's day [skip ci]. References issue #639

    → <<cset fb9d860de680>>

  2. Log in to comment