Last active
May 20, 2018 12:40
-
-
Save thom4parisot/2375d3ac638a6a0c32c2cf1a9c0c4180 to your computer and use it in GitHub Desktop.
loops-refactoring
This file contains hidden or 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 variables = [] | |
function isDuplicate(program, index, programs) { | |
return programs.slice(i+1).contains(p => { | |
return p.program.genrePressCode !== program.program.genrePresseCode | |
}) | |
} | |
function mapProgram({language, idChannel}) { | |
return (program) => ({ | |
url: `/${language}/channel/${idChannel}/show/${program.program.genrePresseCode}`, | |
label: program.program.genrePresse, | |
image: program.program.imageUrl | |
}) | |
} | |
// JSON parsing. | |
const variables = JSON.parse(rawData) | |
.filter(isDuplicate) | |
.map(mapProgram({ language: global.language, idChannel })) | |
} |
This file contains hidden or 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 variables = [] | |
// JSON parsing. | |
const variables = JSON.parse(rawData) | |
.filter((program, i, array) => { | |
return array.slice(i+1).contains(p => { | |
return p.program.genrePressCode !== program.program.genrePresseCode | |
}) | |
}) | |
.map(program => { | |
return { | |
url: `/${global.language}/channel/${idChannel}/show/${program.program.genrePresseCode}`, | |
label: program.program.genrePresse, | |
image: program.program.imageUrl | |
} | |
}) | |
} |
This file contains hidden or 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 variables = [] | |
// JSON parsing. | |
for (const program of JSON.parse(rawData).programs) { | |
if (temp.indexOf(program.program.genrePresseCode) == -1) { | |
variables.push({ | |
url: `/${global.language}/channel/${idChannel}/show/${program.program.genrePresseCode}`, | |
label: program.program.genrePresse, | |
image: program.program.imageUrl | |
}) | |
} | |
} |
Voici la solution :
const variables = JSON.parse(rawData).programs
.filter(program => program.program.genrePresseCode === parseInt(showId, 10))
.map((program) => {
if (program.video) {
programTitle = program.program.genrePresse
return {
url: join(showId, 'video', `${program.video.programId}%2F${program.video.kind}`),
label: `${program.video.title} <span class="h6">[${Math.floor((parseInt(program.video.durationSeconds, 10) / 60))} min]</span>`,
image: program.video.imageUrl,
}
}
})
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
La fonction contains() n'existe pas de base, elle appartient à quel package ?