Created
February 20, 2021 13:39
-
-
Save Frdrcpeter007/9c384b3d9c8c27df455ccedc5019bc6b to your computer and use it in GitHub Desktop.
Cette fonction permet de classe les lettres d'un mot passé en paramètre de la fonction du plus petit au plus grand selon l'alphabet français
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
/** | |
* Cette fonction permet de classe les lettres d'un mot passé en paramètre de la fonction du plus petit au plus grand selon l'alphabet français | |
* @param {String} str La chaine de caractère | |
*/ | |
function alphabetSoup(str) { | |
let letters = str.split(''); | |
return letters.sort((a, b) => { | |
if(a.charCodeAt(0) > b.charCodeAt(0)) return 1 | |
return -1; | |
}).join(''); | |
} | |
module.exports = alphabetSoup; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment