cookie clicker but bigger
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

56 lines
1.3 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. }