I would appreciate some guidance on where my error is.
At the moment, my code finds the word 'he' perfectly and replaces it with 'she'; however for some reason it ignores 'He' with a capital letter at the start of a sentence and replaces it with 'undefined'. I have included the global flag 'i' to ignore case sensitivity, but still, it does not work.
Here is my code:
var mapObj = {
Childname : name,
SchoolName : schoolName,
he : 'she',
his : 'her',
him : 'her',
himself : 'herself',
she : 'he',
her : 'his',
herself : 'himself',
boy : 'girl'
};
Here is where the error likely is.
for (var n = 0; n<data.length;n++) {
let pattern = (gender === 'Male') ? new RegExp (/\b(Childname|SchoolName|she|her|herself|girl)\b/,'gi') : new RegExp(/\b(Childname|he|him|his|himself|boy)\b/,'gi')
let changed = data[n][0].replace(pattern, function(matched){
return mapObj[matched];
});
changedComments.push([changed])
}
destinationSheet.getRange(1,1,changedComments.length,changedComments[0].length).setValues(changedComments)
Any help here would be greatly appreciated.
Thank you!