I have an "required" list of headers in an array that I am wanting to check an object of headers against.
My aim is to get a list of the headers that are missing.
I am wanting this to be case-insensitive.
// For example:
const masterHeads = ['head1', 'head2', 'Head3'];
const headers = {
Heasd1: 'xxx',
Head2: 'yyy',
Head3: 'zzz',
other: 'blah'
};
// output: [ head1 ]
I have so far devised
masterHeads.filter(master => !headers?.[master.toLowerCase()]);
but this seems to be case-sensitive.
2
Answers
UPDATE: This isn't the answer but is perhaps a step to finding it... This does the filtering to find which header(s) are missing, but returns them in lowercase and not in their original case.
I believe I found the answer after thinking about it for a bit longer.
I essentially map each array of the accepted and the header keys to lowercase entirely, then do a check to see if the headers includes the master headers
You could take a
Set
of normalized strings and check against in the filter.