Skip to content

Commit

Permalink
added some error handling for blanks and no matches
Browse files Browse the repository at this point in the history
  • Loading branch information
derekeder committed May 3, 2020
1 parent b832277 commit 751d843
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions obscure_addresses_gsheets.gs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ function processAddress(){

for (addressRow = 1; addressRow <= cells.getNumRows(); addressRow++) {
var address = cells.getCell(addressRow, addressColumn).getValue();

if (!address) {continue}

obscureAddress(cells, addressRow, address);
}
}
Expand All @@ -25,17 +28,26 @@ function obscureAddress(cells, row, address){
// pluck first set of digits at the beginning of the address string
var myregexp = /^\d+/g;
var match = myregexp.exec(address);
var street_num = match[0];

// replaces last 2 digits with zeroes
var street_num_obscured = street_num.slice(0, -2) + "00";

// return obscured address
var obscured_address = address.replace(street_num, street_num_obscured);

insertDataIntoSheet(cells, row, [
[outputColumn, obscured_address]
]);

if (!match) {
insertDataIntoSheet(cells, row, [
[outputColumn, address]
]);
}
else {

var street_num = match[0];

// replaces last 2 digits with zeroes
var street_num_obscured = street_num.slice(0, -2) + "00";

// return obscured address
var obscured_address = address.replace(street_num, street_num_obscured);

insertDataIntoSheet(cells, row, [
[outputColumn, obscured_address]
]);
}
}

/**
Expand Down

0 comments on commit 751d843

Please sign in to comment.