Last active
August 13, 2018 12:12
-
-
Save AlfieDarko/76de4db1d4a6a18be448765310148611 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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