Skip to content

Instantly share code, notes, and snippets.

@arturovt
Created June 6, 2019 23:25
Show Gist options
  • Select an option

  • Save arturovt/8f6674adb0b2e3d9b6269f0e9dbc4396 to your computer and use it in GitHub Desktop.

Select an option

Save arturovt/8f6674adb0b2e3d9b6269f0e9dbc4396 to your computer and use it in GitHub Desktop.
export class CountriesService implements Mutateble<Country> {
public mutateSource(
countries: Country[],
key: keyof Country,
value: Country[keyof Country]
): Country[] {
countries.forEach((country) => {
country[key] = value;
}); // BAD
for (const country of countries) {
country[key] = value;
} // GOOD
for (let i = 0, length = countries.length; i < length; i++) {
const country = countries[i];
country[key] = value;
} // GOOD
return countries;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment