Skip to content

Instantly share code, notes, and snippets.

@chilversc
Last active Dec 18, 2015
Embed
What would you like to do?
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