Last active
November 20, 2018 16:49
-
-
Save tofl/bfae4d06e710df07e04190fedcd7c02d to your computer and use it in GitHub Desktop.
Agorithmes cools
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
// 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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment