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 countLetters = (str) => { | |
| // convert the string to an array | |
| return [...str].reduce( | |
| (acc, curr) => | |
| // check if character has been seen before | |
| acc.hasOwnProperty(curr) | |
| ? { ...acc, [curr]: acc[curr] + 1 } // + 1 | |
| : { ...acc, [curr]: 1 }, // add it to the object with a count of 1 | |
| {} // start with an empty object | |
| ); |
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
| /* Box sizing rules */ | |
| *, | |
| *::before, | |
| *::after { | |
| box-sizing: border-box; | |
| } | |
| /* Remove default margin */ | |
| body, | |
| h1, |
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 generateRandomHexColor = () => `#${Math.floor(Math.random() * 0xffffff).toString(16)}`; |
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 shuffleArray = (arr) => arr.sort(() => Math.random() - 0.5); | |
| // Testing | |
| const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
| console.log(shuffleArray(arr)); // OUTPUT : [ 10, 6, 2, 4, 9, 1, 3, 7, 5, 8 ] |
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 getUnique = (arr) => [...new Set(arr)]; | |
| const arr = [1, 1, 2, 3, 3, 4, 4, 4, 5, 5]; | |
| console.log(getUnique(arr)) // >>> OUTPUT : [ 1, 2, 3, 4, 5 ] |
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
| 1. Créer un dossier et se placer dedans | |
| 2. Cliquer dans la barre de tâche windows du dossier (elle devient bleue) | |
| 3. Taper "cmd" puis "enter" | |
| 4. Dans le Shell : | |
| > commencer un GIT : "git init" | |
| > Ajouter : "git add ." | |
| > Vérifier que tout est ok : "git status" | |
| > Faire un commit (ne pas oublier le message) : 'git commit -m "ici le message"' | |
| > Une fois le message écrit on tape sur "enter" | |
| > Pour voir tous les commit : "git log" |
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
| // SOLUTION 1 | |
| function myReplace(str, before, after) { | |
| // Find index where before is on string | |
| var index = str.indexOf(before); | |
| // Check to see if the first letter is uppercase or not | |
| if (str[index] === str[index].toUpperCase()) { | |
| // Change the after word to be capitalized before we use it. | |
| after = after.charAt(0).toUpperCase() + after.slice(1); | |
| } else { | |
| // Change the after word to be uncapitalized before we use it. |
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
| function whatIsInAName(collection, source) { | |
| let srcKeys = Object.keys(source); | |
| return collection.filter((obj) => srcKeys.every((key) => obj.hasOwnProperty(key) && obj[key] === source[key])); | |
| // On filtre la collection en utilisant ".filter()" | |
| // Ensuite, on retourne une valeur booléenne pour la méthode ".filter()" | |
| // Enfin, on réduit la valeur booléenne à renvoyer pour la méthode ".every()" | |
| }; |
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
| function alphabeticalOrder(arr) { | |
| return arr.sort((a, b) => a === b ? 0 : a > b ? 1 : - 1); | |
| }; | |
| alphabeticalOrder(["a", "d", "c", "a", "z", "g"]); |
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
| function count(str) { | |
| // On met tout en minuscule | |
| str = str.toLowerCase(); | |
| // On met tout dans un tableau | |
| let arr = str.split(''); | |
| // On compte la lettre souhaitée (par ex. le "A") : | |
| let count_A = arr.reduce((n, val) => { |
NewerOlder