Skip to content

Instantly share code, notes, and snippets.

@onliniak
Created January 22, 2021 11:36
Show Gist options
  • Select an option

  • Save onliniak/29beea47949223624a0240ac950e5348 to your computer and use it in GitHub Desktop.

Select an option

Save onliniak/29beea47949223624a0240ac950e5348 to your computer and use it in GitHub Desktop.
Prosty kalkulator
let obliczenia = 0;
math = {}
math.dodaj = 5
math.razy = 3
function oblicz(matm) {
sort = Object.entries(matm).sort((k, v) => k[0].localeCompare(v[0]));
for (i = 0; i < sort.length; i++) {
switch (sort[i][0]) {
case "dodaj":
obliczenia = obliczenia + sort[i][1]
break;
case "razy":
obliczenia = obliczenia * sort[i][1]
break;
}
}
return obliczenia
}
h = oblicz(math)
console.log(h) # → 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment