I've built a program that tracks grades in a school, and which students belong to each grade. One of the class's methods, roster(), returns the school roster after it sorts the students alphabetically. In the tests, I'm trying to see if the school roster can be modified outside of the class, specifically by calling roster(), storing this object, and modifying it. This is possible because JavaScript is returning a reference to my this._roster object. For the test to pass, I must be unable to modify the returned object. Credit: I'm working on a project from exercism.io Here's my code: export class GradeSchool {   constructor() {     this._roster = {};   }    roster() {     const keys = Object.keys(this._roster);     for (let i = 0; i &lt; keys.length; i++) {       this._roster[keys[i]].sort();     }     return this._roster;   }    add(name, grade) {     if(this._roster.hasOwnProperty(grade)) {       this._roster[grade].push(name);     } else {       this._roster[grade] = [name];     }   } }  And my test: test('roster cannot be modified outside of module', () =&gt; {     school.add('Aimee', 2);     const roster = school.roster();     roster[2].push('Oops.');     const expectedDb = { 2: ['Aimee'] };     expect(school.roster()).toEqual(expectedDb);   });  I tried modifying my roster() as shown: ... which technically no longer modifies the this._roster object, but obviously still doesn't work as it stills passes an object by reference, which is stored and modified outside of the module. roster() {     const duplicateRoster = {};     const keys = Object.keys(this._roster);     for (let i = 0; i &lt; keys.length; i++) {       duplicateRoster[keys[i]] = this._roster[keys[i]].sort();     }     return duplicateRoster;   }  I've been researching how I can return an object by value and not by reference. I've been unsuccessful in finding an answer, however. If somebody knows how, please show me here. If it isn't possible, can somebody please explain how I can make my this._roster object private/unaccessible outside of the module?
What is the most efficient way to clone a JavaScript object? I've seen obj = eval(uneval(o)); being used, but . I've done things like obj = JSON.parse(JSON.stringify(o)); but question the efficiency.  I've also seen recursive copying functions with various flaws.  I'm surprised no canonical solution exists.
Do not load Facebook-based avatars directly from the Facebook CDN Users who register for their account via Facebook get  as their default avatar. However, the avatar is not copied to SE servers or Imgur, and thus the original URL is kept. This URL compromises the privacy of the user as it contains their Facebook user ID which everyone can easily extract and then view the profile.  The image is also not visible at all to those who have Facebook blocked for their own privacy (by extensions such as Ghostery or browser features ), or due to network policy (e.g. some work and school networks block Facebook).  With the new avatar system, it would be much better if the Facebook photo was stored like a manually uploaded avatar to avoid this problem. How many different (circular) garlands can be made using $3$ white flowers and $6m$ red flowers? This is my first question here.   I'm given $3$ white flowers and $6m$ red flowers, for some $m \in \mathbb{N}$. I want to make a circular garland using all of the flowers. Two garlands are considered the same if they can be rotated to be the same. My question is: how many different garlands can I make?  I tried an approach in which I divided the question into three parts:   No. of ways in which the white flowers are all together No. of ways in which two white flowers are together No. of ways in which no two white flowers are together   Can you please help?  The answer is $3m^2+3m+1$ in the book that I saw  Thanks How to move from screen 1 to screen 3 by moving cursor to the left and vice versa? If I have to move the mouse from the left screen all the way to the right screen, the distance is quite big.   Is there a way to virtually connect the sides of the screen as if they were arranged in a circle? I could then move from the left screen to the right screen, by simply moving the cursor to the left. Are fractions with prime numerator and denominator dense? So the question is in the title. And I mean dense in positive real numbers ofcourse. Somehow I cannot grasp if this is very trivial or not. The prime numbers aren't that dense, but are there enough of primes to make the fractions constructed from them dense? Prove $\frac{1}{1 \cdot 3} + \frac{1}{3 \cdot 5} + \frac{1}{5 \cdot 7} + \cdots$ converges to $\frac 1 2 $ Show that $$\frac{1}{1 \cdot 3} + \frac{1}{3 \cdot 5} + \frac{1}{5 \cdot 7} + \cdots = \frac{1}{2}.$$  I'm not exactly sure what to do here, it seems awfully similar to Zeno's paradox. If the series continues infinitely then each term is just going to get smaller and smaller.  Is this an example where I should be making a Riemann sum and then taking the limit which would end up being $1/2$? Is there a standard delay for consumer ratings of apps on the App Store? I have an app that's been out for a couple of weeks. Its not exactly selling like hot cakes yet, but I'm pretty sure I've gotten a rating or a review by now. But nothing shows when viewing either in iTunes or directly on the AppStore on the iPhone.  Is there a standard delay as to when ratings/reviews show up, that Apple imposes, especially for new apps? Or do you think there is some problem with Apple's system? I have two tables in my database:  NEWS table with columns:   id - the news id  user - the user id of the author)   USERS table with columns:   id - the user id   I want to execute this SQL:   SELECT * FROM news JOIN users ON news.user = user.id    When I get the results in PHP I would like to get associative array and get column names by $row['column-name']. How do I get the news ID and the user ID, having the same column name? I see all of these software that claim that they can recover messages deleted from your iPhone. Do they actually work?  For example, if I received 2 text messages from my friend and I immediately deleted them. Is it possible to recover them? What are the system requirements for each flavour of Ubuntu Desktop? I'm thinking about installing Ubuntu Desktop, but I don't know what flavor is the best for my system. What are the minimum and recommended hardware requirements? What kind of CPU? How much memory? Should I have Hardware Acceleration? What flavor should I use?  This is an attempt of a canonical answer. My answers have the &quot;official  requirements&quot;, the recommended are a mix of official sources and opinion based (along with the answer it's told the source). You can comment or edit if you feel that the information is obsolete or incomplete. It is a good rule of thumb that any system capable of running Windows Vista, 7, 8, x86 (Intel) OS X will almost always be a lot faster with any Ubuntu flavor even if they are lower-spec than described below. how to extract multiple zipped and rar files recursively? I have a folder ExampleFolder which contains many zipped folders. These zipped folders also contains multiple zipped folders. How to go through ExampleFolder and extract all of its zipped folders recursively?   Note that ExampleFolder itself, is not zipped, it's just a normal folder  Okay now I know what's happening Rinzwind and nux answers are both correct (except that I have to keep pressing Y or A forever)  But it's seems that some of the zipped files, contained zipped files and rar files as well, the rar files will not be extracted by   while [ "`find . -type f -name '*.zip' | wc -l`" -gt 0 ]; do find -type f -name "*.zip" -exec unzip -- '{}' \; -exec rm -- '{}' \;; done    or whatever  Edit 2 Some files are named .r00 and r01, .r02 up to r14, they are rar files, but not .rar Keep iphone active while running program how to set iPhone device to stay active ( to not lock ) while my app is running ? Any idea Effects of continuing after a total party wipe? I've had a couple of encounters so far where I stumbled into enemies that were higher level than expected and gotten wiped out. At the game over screen, I chose the option "Continue". After doing so, I didn't notice any negative consequences. I was plopped back just a few metres from the area I died, and was free to continue on as if nothing had happened. Am I missing something? Is there some negative effect from a party wipe? Overview of basic facts about Cauchy functional equation Unique quadratic subfield of $\mathbb{Q}(\zeta_p)$ is $\mathbb{Q}(\sqrt{p})$ if $p \equiv 1$ $(4)$, and $\mathbb{Q}(\sqrt{-p})$ if $p \equiv 3$ $(4)$ On Takodana,      the main characters and various bar patrons can see the planet Hosnian Prime being destroyed by Starkiller Base with their (respective) naked eyes. How did they see this? Is the Hosnian system close enough to see? If it's not very close and they could just see the explosion, how did the light from it reach them so quickly? How to choose which FaceTime number to call I have a friend with two iPhones, two different numbers.  When I call her with FaceTime audio, only phone A rings.  How can I call phone B?  The phones have two separate Apple ID addresses, but they are both set to receive Facetime calls on their 10 digit phone numbers.  I have both numbers listed in my contacts as 'Home' and 'Work' for the same person. How to change the href for a hyperlink using jQuery How can you change the href for a hyperlink using jQuery? Is it possible to create a counter just with wiring? With the new logic gates in the 1.3.1 update, is it possible to create some wiring circuit that counts how many times a trigger was activated? In other words, is it possible to make a circuit that outputs a trigger every two input triggers?  I've done some experimenting but the nature of wires and there being no intrinsic on/off state in Terraria makes it pretty counter-intuitive compared to real world logic circuits. Can't start ubuntu-desktop after upgrade to 18.04 After the restart step of upgrading Ubuntu to 18.04, tty is opening instead ubuntu-desktop. And when I enter my login name and password, I am still in the tty. This is happening again in every restart. How can I start the graphical desktop as normal? In most electrical circuits with a relay, a diode is connected in parallel to the coil of the relay. Why? Is it always a good practice?