Skip to content

Instantly share code, notes, and snippets.

@tofl
Last active November 20, 2018 16:49
Show Gist options
  • Save tofl/bfae4d06e710df07e04190fedcd7c02d to your computer and use it in GitHub Desktop.
Save tofl/bfae4d06e710df07e04190fedcd7c02d to your computer and use it in GitHub Desktop.
Agorithmes cools
// 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