Skip to content

Instantly share code, notes, and snippets.

@chilversc
Last active December 18, 2015 11:30
Show Gist options
  • Save chilversc/e732391066e12ec37b82 to your computer and use it in GitHub Desktop.
Save chilversc/e732391066e12ec37b82 to your computer and use it in GitHub Desktop.
addHost() {
var header = { key: this.hostHeaderKey, value: this.hostHeaderValue };
if (!this.hasHeader(header)) {
this.hostHeaders.push(header);
this.hostHeaderKey = '';
this.hostHeaderValue = '';
}
};
hasHeader(header) {
// though I'd change hasElement to return boolean, and then just:
// return this.hasElement(this.hostHeaders, header, 'key');
var index = this.hasElement(this.hostHeaders, header, 'key');
// purposfully split fetching the index and the comparison to make it obvious
// otherwise a random >= 0 at the end could be missed when scanning the code.
return index >= 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment