Skip to content

Instantly share code, notes, and snippets.

@lazywithclass
Last active December 15, 2015 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazywithclass/6b6a14699aeed656e55e to your computer and use it in GitHub Desktop.
Save lazywithclass/6b6a14699aeed656e55e to your computer and use it in GitHub Desktop.
// review https://gist.github.com/lazywithclass/f42aab0ca8af0f17d5e8
// strings
// operations on strings
// given a string like this
// "1+2-5"
// use the above functions implemented in the exercise
// to provide the result
function suddividi(operazione) {
return operazione.split('+');
}
function somma(a, b) {
return parseInt(a, 10) + parseInt(b, 10);
}
function calcolatrice(operazione) {
var suddivisa = suddividi(operazione);
return somma(suddivisa[0], suddivisa[1]);
}
// far funzionare
// suggerimento, usa sempre split, niente altro
// calcolatrice("1+2+3")
// calcolatrice("7+14+2")
// in modo che restituisca 6
// calcolatrice("1+2-3")
// calcolatrice("16+23-13")
// in modo che restituisca 6
// calcolatrice("1+2*3")
// in modo che restituisca 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment