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.
 
 
 
 

42 lines
955 B

  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. }