Last active
September 12, 2018 18:53
-
-
Save pierreroth64/5c782341c80dcf685a41ab7142ea17e0 to your computer and use it in GitHub Desktop.
map usage
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
/* | |
- cycleLines() est la fonction originelle. Tu utilises un tableau intermédiaire returnValue | |
mais ce dernier est inutile puisque map te renvoie un tableau (cf. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) | |
- cycleLines1() est un rework qui fait le job mais en utilisant map de façon idiomatique | |
- cycleLines2() va un peu plus loin en utilisant une facilité syntaxique de JS qui permet de retourner une valeur en omettant | |
le return | |
Plus concis et donc facile à lire, n'est-ce pas ? ;-) | |
*/ | |
function cycleLines() { | |
let returnValue = []; | |
peakFlowVolumeMonitoringSeries.map((element, index) => { | |
returnValue.push( | |
cycleLine( | |
index + 1, | |
element, | |
tidalVolumeMonitoringSeries[index], | |
pmaxMonitoringSeries[index] | |
) | |
); | |
}); | |
return returnValue; | |
} | |
function cycleLines1() { | |
return peakFlowVolumeMonitoringSeries.map((element, index) => { | |
return cycleLine( | |
index + 1, | |
element, | |
tidalVolumeMonitoringSeries[index], | |
pmaxMonitoringSeries[index] | |
); | |
}); | |
} | |
function cycleLines2() { | |
return peakFlowVolumeMonitoringSeries.map((element, index) => | |
cycleLine( | |
index + 1, | |
element, | |
tidalVolumeMonitoringSeries[index], | |
pmaxMonitoringSeries[index] | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment