Skip to content

Instantly share code, notes, and snippets.

@SebDuf
Last active July 29, 2019 15:48
Show Gist options
  • Save SebDuf/7dc609b258b2a933201ee2c6fbc450f9 to your computer and use it in GitHub Desktop.
Save SebDuf/7dc609b258b2a933201ee2c6fbc450f9 to your computer and use it in GitHub Desktop.
// Before
function getUserFriends(state): Friends[] {
return state.me.friends;
}
// After
function getUserFriends(state): Friends[] {
const friends = [];
// Please never do this; it's only to illustrate the point
for (let count = state.me.friendCount; i <= state.me.friendCount; i++) {
friends.push(state.me[`friend-${count}`]);
}
return friends;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment