Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Closure
- function multiplicateur(facteur) {
- return nombre => nombre * facteur;
- }
- let doubler = multiplicateur(2);
- alert(doubler(10));
- // Détermine une séquence d'additions de 5 et de multiplications par 3 pour obtenir un nombre n spécifié en paramètres :
- function findSolution(target)
- {
- function find(current, history)
- {
- if (current == target) {
- return history;
- } else if (current > target) {
- return null;
- } else {
- return find(current + 5, `(${history} + 5)`) || find(current * 3, `(${history} * 3)`);
- }
- }
- return find(1, "1");
- }
- alert(findSolution(24));
Add Comment
Please, Sign In to add comment