Usecase reduce : Closest
🚀Quelle couleur est la plus proche de 610 ?
const table = new Map([
[0,'yellowgreen'],
[150, 'green'],
[600, 'olive'],
[750, 'red'],
[800, 'black'],
]);
Solution :
const closestKey = [...table.keys()].reduce( (acc, key) => {
return acc = ( Math.abs(acc-value) < Math.abs(key-value) ) ? acc : key
})
console.log(`the closest value of ${value} is ${table.get(closestKey)}`
Liste de projets
Pour info :
https://docs.google.com/document/d/10h_6uHYvPKyLtQPNlUNkr7L_jqS98r0AD3PlAvsHE2g/edit?usp=sharing
https://docs.google.com/document/d/1t0oOJ5Vo2AmxwvLodTaobpY7BOs0_QPIME23wAx08SA/edit?usp=sharing
https://docs.google.com/document/d/1PUUE7HBeqJ2hDh6c5MxJsBS3N0W2xl83l0kaVofl4V4/edit?usp=sharing
https://docs.google.com/document/d/1DYadNNz9MejGkKGWo31DCLhT_Nxnbh94vohXyDaJ_YY/edit?usp=sharing
https://docs.google.com/document/d/1EU2hY-ZjEGV0E9VQVuYry4n_ohApN0OGEfWp1hONrNI/edit?usp=sharing
https://docs.google.com/document/d/1En2R7iD3RabNgeSjYjjofCVxKjXglSNH8_34qgD54SQ/edit?usp=sharing
https://docs.google.com/document/d/1U7StYdejEdcYjezKIkgukU23awAz4nwWLzNq6AF54YY/edit?usp=sharing
