Skip to content

Instantly share code, notes, and snippets.

@AlfieDarko
Last active August 13, 2018 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlfieDarko/76de4db1d4a6a18be448765310148611 to your computer and use it in GitHub Desktop.
Save AlfieDarko/76de4db1d4a6a18be448765310148611 to your computer and use it in GitHub Desktop.
const manUTD = [
"David de Gea",
"Victor Lindelöf",
"Eric Bailly",
"Phil Jones",
"Marcos Rojo",
"Paul Pogba",
"Alexis Sánchez",
"Juan Mata",
"Romelu Lukaku",
"Anthony Martial",
"Axel Tuanzebe",
"Scott McTominay",
"Joel Castro Pereira",
"Cameron Borthwick-Jackson",
"Diogo Dalot"
]
const manchesterUnitedInjuryArray = ["Juan Mata", "Joel Castro Pereira", "Marcos Rojo", "Phil Jones", "Eric Bailly", "Alexis Sánchez", "Anthony Martial", "Cameron Borthwick-Jackson"]
function giveMeNonInjuredPlayers(wholeTeam,injuredPlayers)
{
let result = wholeTeam.filter((player) =>
!injuredPlayers.includes(player) );
return result;
}
const fitPlayers = giveMeNonInjuredPlayers(manchesterUnitedArray, manchesterUnitedInjuryArray)
console.log(fitPlayers)
// Expected output:
// [ 'David de Gea',
// 'Victor Lindelöf',
// 'Paul Pogba',
// 'Romelu Lukaku',
// 'Axel Tuanzebe',
// 'Scott McTominay',
// 'Diogo Dalot' ]
// You can see that fitPlayers is a new array that is a transformation of the manchesterUnitedArray
console.log(manchesterUnitedArray)
// Expected output:
// [
// "David de Gea",
// "Victor Lindelöf",
// "Eric Bailly",
// "Phil Jones",
// "Marcos Rojo",
// "Paul Pogba",
// "Alexis Sánchez",
// "Juan Mata",
// "Romelu Lukaku",
// "Anthony Martial",
// "Axel Tuanzebe",
// "Scott McTominay",
// "Joel Castro Pereira",
// "Cameron Borthwick-Jackson",
// "Diogo Dalot"
// ]
// The transformation array is wholly intact and untouched
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment