cookie clicker but bigger
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

69 řádky
1.6 KiB

  1. function replaceChildren(element, newChildren) {
  2. removeChildren(element);
  3. addChildren(element, newChildren);
  4. }
  5. function addChildren(element, children) {
  6. for (let child of children) {
  7. element.appendChild(child);
  8. }
  9. }
  10. function removeChildren(element) {
  11. while (element.lastChild) {
  12. element.removeChild(element.lastChild);
  13. }
  14. }
  15. function round(val, places = 0) {
  16. return Math.round(val * Math.pow(10, places)) / Math.pow(10, places);
  17. }
  18. function mapObject(obj, func) {
  19. return deepFreeze(Object.keys(obj).reduce((o, k) => ({ ...o, [k]: func(obj[k])}), {}));
  20. }
  21. function deepFreeze(object) {
  22. // Retrieve the property names defined on object
  23. var propNames = Object.getOwnPropertyNames(object);
  24. // Freeze properties before freezing self
  25. for (let name of propNames) {
  26. let value = object[name];
  27. object[name] = value && typeof value === "object" ?
  28. deepFreeze(value) : value;
  29. }
  30. return Object.freeze(object);
  31. }
  32. function showBuilding(key) {
  33. let count = belongings[key].count;
  34. let name = count == 1 ? buildings[key].name : buildings[key].plural;
  35. return count + " " + name.toLowerCase()
  36. }
  37. function capitalize(string) {
  38. return string[0].toUpperCase() + string.slice(1)
  39. }
  40. function weekday() {
  41. return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][(new Date()).getDay()];
  42. }
  43. function weightedSelect(weights) {
  44. const total = weights.reduce((x,y) => x+y, 0);
  45. const rand = Math.random() * total;
  46. let counter = weights[0];
  47. let index = 0;
  48. while (counter < rand) {
  49. index += 1;
  50. counter += weights[index];
  51. }
  52. return index;
  53. }