Deep clone array of objects I have a javascript object that maintains an internal array of objects. I have a method that returns the array but I need to prevent external manipulation of the array and the objects inside it.  Trying slice to copy the array but I've noticed that the objects inside are still references to the originals while the array itself is new. I've never noticed this before, but I've confirmed it:  function test(){      // I want this to be safe from outside influence     var a = [{         val: 1        },{         val: 2        }];      return {         all: function(){             return a.slice();         }     } }  var instance = test(); var copy = instance.all();  // This affects both "copy" and the original copy[0].val = 'wrong';  // This clears "copy" but doesn't affect the original copy = [];     I need to have a truly new copy so an outsider can't modify the array without using the API methods I've designed. I assume all I can do iterate the array and use $.extend (or similar methods from other libs) to clone the objects individually - is there any easier/native alternative?
What is the most efficient way to deep clone an object in JavaScript? 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.
Using Zorn's lemma show that $\mathbb R^+$ is the disjoint union of two sets closed under addition. Let $\Bbb R^+$ be the set of positive real numbers. Use Zorn's Lemma to show that $\Bbb R^+$ is the union of two disjoint, non-empty subsets, each closed under addition. How do I enable the "partner" repository? I keep seeing places refer to the "partner" repository as a place I can get software, how can I enable this repository? Please specify how to do this graphically and via command line. How to look up a symbol or identify a letter from a math alphabet or other character? I know what my symbol or character looks like, but I don't know what the command is or which math alphabet it came from. How do I go about finding this out? How can I pad an integer with zeros on the left? How do you left pad an int with zeros when converting to a String in java?  I'm basically looking to pad out integers up to 9999 with leading zeros (e.g. 1 = 0001). Captured variable in a loop in C# I met an interesting issue about C#. I have code like below.  List&lt;Func&lt;int&gt;&gt; actions = new List&lt;Func&lt;int&gt;&gt;();  int variable = 0; while (variable &lt; 5) {     actions.Add(() =&gt; variable * 2);     ++ variable; }  foreach (var act in actions) {     Console.WriteLine(act.Invoke()); }   I expect it to output 0, 2, 4, 6, 8. However, it actually outputs five 10s.  It seems that it is due to all actions referring to one captured variable. As a result, when they get invoked, they all have same output.  Is there a way to work round this limit to have each action instance have its own captured variable? What command can I type into the Terminal so that I can delete all .svn folders within a folder (and from all subdirectories) but not delete anything else? BibTeX handling of the Dutch "van" name prefix with natbib Bash script to remove the oldest file from from a folder I want to make a bash script to delete the older file form a folder. Every time when I run the script will be deleted only one file, the older one. Can you help me with this? Thanks Cron Job not working in plugin I have written a plugin that will convert posts to excel format and then email the .xls to an email id. I can make it work with when function is declared in functions.php but does not work with function defined in plugin file.   if ( ! wp_next_scheduled( 'xls_func_hook1' ) ) {   wp_schedule_event( time(), 'hourly', 'xls_func_hook1' ); }  add_action( 'xls_func_hook1', 'sendxls1' ); //senxls1 is a function in functions.php if ( ! wp_next_scheduled( 'xls_func_hook2' ) ) {    wp_schedule_event( time(), 'hourly', 'xls_func_hook2' ); } add_action( 'xls_func_hook2', 'export2excel' );   The full code is at How to make a circular array using offset object as center? How to add new element to Varargs? Arriving at a different port of entry in the same state in USA? I am a girl in my early twenties traveling to USA from India and in my visa application I have provided the contact address for a relative in San Francisco, and their invitation letter. I would like to visit LA first. Will I face problems during immigration if I land in LA (with an immediate on wards ticket to SF)? I dont plan to get on the flight from LA to SFO.  Initially I was planning to fly to SFO from India and then fly to LA immediately after completing immigration at SFO airport. I've seen in every introductory material on LaTeX and in a lot of code of other people (event experts) that the \newcommand command is used by wrapping the first argument in braces, even if it seems unnecessary to me.   The braces are consistent with the usual way arguments are passed to LaTeX commands (since usually the braces are used even if the argument is made of a single token, for consistency and clarity), but in this single case they appear very ugly to me and in my opinion they lower readability.  But these are opinions, while the question is technical: is there any technical reason why one should write this:  \newcommand{\mycmd}[1]{Hello #1}   instead of this:  \newcommand\mycmd[1]{Hello #1} Intuition for why the sum of Bernoulli trials is a sufficient statistic via cancellations on numerator and denominator? Suppose that $X_1, \ldots, X_n$ are iid Bernoulli trials with parameter $p$, and that $Y = \sum_{i=1}^nX_i$. Then, we have that $Y$ is a sufficient statistic by the following condensed proof:  $$ P(X_1 = x_1,  ... , X_n = x_n |Y = y) = \frac{p^y(1-p)^{n-y}}{\binom{n}{y}  p^y(1-p)^{n-y}} =\frac{1}{\binom{n}{y}}   \text{ if } \sum_{i=1}^{n}x_i = y $$  I am trying to see why this is the case. My reasoning is that there is some cancellation property on top and bottom that "kills" off the parameter $p$. In that whatever is on top through $p$ is perfectly matched by whatever is on the bottom minus scaling factors (in this case $\binom{n}{y}^{-1}$).   However, I am wondering what the deeper meaning behind this is, that the numerator of the joint distribution of the data and the sufficient statistic has its EXACT form on the bottom, except for constants which are only multiplicative (to facilitate cancellations). Am I onto something bigger and deeper here? How to delete directories with path/names too long for normal delete Moving from HTTP to HTTPS in Google Search Console Keyboard shortcut to autocomplete the user in comments Dismiss suggested edits which conflict with full edit instead of auto rejecting them Currently, once an edit by a user without full edit privilege is suggested, it can be either approved or rejected.  There is a known edge case that cause suggested edits to get auto rejected: (aka edit conflict)   User with full edit privilege click "edit" and start typing. Let's name this user Joe. Since the user from previous step did not yet send the edit, users without full edit privilege can still click the "edit" as well, oblivious to the fact someone else is editing the same post in those very seconds. Such user click "edit" too and start typing. Let's name this user Kenny. Kenny is faster than Joe: he send his edit first, creating new suggested edit. Joe is still typing. Joe finally done typing. He send his edit to its merry way oblivious to the consequences. As result of the full edit made by Joe, Kenny's suggested edit is kicked away and rejected. Boom.   This is all known and reported many times.  where the user got it hard with at least two auto rejections in short period of time. Some concrete examples: , , .  For edge case, it became pretty thick edge. This is not just minor hassle: enough rejections, and the user is banned from suggesting for a whole week: and remember we're talking here about good edits made by good users. The above used to count for the ban, but . Thanks Gilles for requesting such a change!   I know it was already suggested to lock edits and similar solutions, but I suggest whole different approach: instead of auto rejecting the suggested edit, dismiss it, i.e. cancel it like it never existed same way a bounty can be revoked by moderator.  In the edit suggestion page it will show "Dismissed" instead of Approved or Rejected maybe with a tooltip explaining what caused this. This will soften the blow from those edge cases, taking the edge out of them. :) Writing ISO 19139 compliant XML metadata from spreadsheet? I am looking at a way to migrate the metadata from a spreadsheet into ISO 19139 compliant XML metadata documents for a collection of shapefiles. I can parse the data out of the spreadsheet into strings without issue however I am getting lost on how to take those strings and use them to populate the elements.   This example:  covers most of what I want to do, however I would need to generate the tree beforehand based on the ISO 19139 schema. PyXB seems to have schema bundles for OpenGIS but I would like some insight on how to connect everything. Recently, I have noticed that on most applications I have on Ubuntu 16.04, when I load the application, the window is displayed with a strange multi-coloured border (see the images below). If I maximise the window though, the border disappears and the window is displayed as expected.  This started happening for no apparent reason. If I reboot my machine, things return to normal at first, but after a while the problem comes back.  The issue occurs on most applications, including Nautilus, Software Centre, Terminal, System Settings, etc... I also get the same border appearing when I right click on the desktop, with the border surrounding the pop-up menu.  However, I have noticed that it does not happen on Chrome, but it does happen on other applications which did not come with Ubuntu by default.  Any ideas on what is causing the problem? Thanks!