I have two javascript arrays. I need to copy the array values from one another. I have used code like below.  javascript    let firstArr = [{name: "one"},{name: "two"}]; let secondArr = [...firstArr]; secondArr[0].name = "three"; console.log(firstArr) console.log(secondArr)     I have changed only "secondArr" values. But first array values are also changed. I have used the spread operator, so it will create a new memory then why the first array values are also changed?  Could you please anyone explain this. Thanks in advance.
...where each object also has references to other objects within the same array?  When I first came up with this problem I just though of something like   var clonedNodesArray = nodesArray.clone()   would exist and searched for info on how to clone objects in javascript. I did find a  on StackOverflow (answered by the very same @JohnResig) and he pointed out that with jQuery you could do  var clonedNodesArray = jQuery.extend({}, nodesArray);   to clone an object. I tried this though, this only copies the references of the objects in the array. So if I   nodesArray[0].value = "red" clonedNodesArray[0].value = "green"   the value of both nodesArray[0] and clonedNodesArray[0] will turn out to be "green". Then I tried  var clonedNodesArray = jQuery.extend(true, {}, nodesArray);   which deep copies an Object, but I got "too much recursion" and "control stack overflow" messages from both Firebug and Opera Dragonfly respectively.  How would you do it? Is this something that shouldn't even be done? Is there a reusable way of doing this in Javascript?
Code coverage for wrapper class is 0% I have written below Wrapper class.  global class BI_VA_AutomationWrapper {      global class BI_VA_AutomationRequest {      webservice String userName;     webservice String emailId;     webservice String buinessUnit;     webservice String orgName;     webservice String country;     webservice String environment;     webservice String myShopNumber;     webservice String BidsId;//for testing     webservice String Type; //for testing  }  global class BI_VA_AutomationResponse {      webservice String responseStatus;     webservice String myShopNumber;     //webservice list&lt;Error&gt; errorMessages;     webservice String  errorMessages;//for testing   } global class BI_VA_Error {      webservice String type;     webservice String message;    }}   And test class is,  @isTest public class BI_VA_AutomationWrapperTestClass  { public static testMethod void unitTest(){      BI_VA_AutomationWrapper.BI_VA_AutomationRequest wrap= new BI_VA_AutomationWrapper.BI_VA_AutomationRequest();        wrap.userName='Test@test.com';     wrap.emailId='Test@test11.com';     wrap.buinessUnit='AH';     wrap.orgName='ORD';     wrap.country='US';     wrap.environment='QA';     wrap.myShopNumber='123456789';     wrap.BidsId='123';     wrap.Type='ResetPassword';              BI_VA_AutomationWrapper.BI_VA_AutomationResponse res= new BI_VA_AutomationWrapper.BI_VA_AutomationResponse();     res.responseStatus = 'Success';     res.myShopNumber = '987654321';     res.errorMessages = 'Test error';      BI_VA_AutomationWrapper.BI_VA_Error error = new BI_VA_AutomationWrapper.BI_VA_Error();     error.type = 'Test';     error.message = 'Test';  }}   Code coverage is 0% only. How to fix a stripped pedal crank The threads on my bike's pedal crank just became fully stripped and the pedal fell off, though the pedal itself is fine. Is there any way I can fix this without fully replacing the pedal crank? I am trying to proof the following algorithm to see if a there exists a path from u to v in a graph G = (V,E).   Reach := {u} LastCardinality := 0 while LastCardinality &lt; |Reach| do   LastCardinality := |Reach|   Next := null   foreach i &lt;- Reach do     foreach j &lt;- V do       if(i,j) exists in E then         Next := Next + {j}   Reach := Reach + Next return Reach   So far I have got that the output needs to be Reach = Goal where Goal = {r | r exists V, there is a path from u to r}. I also have three invariants that I am pretty sure will help prove this.   Reach is always a subset of Goal and Next is always a subset of Goal. After an arbitrary K times through the while loop, for every t that exsits in V, if t has a path of length k+1 from u, then t exists in Reach If Reach is a subset of Goal before the while loop then LastCardinality &lt; |Reach|   I know that to finish up the proof, I need to prove termination, the invariants, and correctness but I have no idea how. I think I need to use induction on the while loop but I am not exactly sure how.   How do I proof those three characteristics about an algorithm? I have a question regarding the two QGIS Versions 2 and 3. When I load exactly the same raster file into QGIS 2 and QGIS 3 I get different min/max values, how is this possible? I have used the same coordination system. If $f: \mathbb Q\to \mathbb Q$ is a homomorphism, prove that $f(x)=0$ for all $x\in\mathbb Q$ or $f(x)=x$ for all $x$ in $\mathbb Q$.  I'm wondering if you can help me with this one? Do I need a bus/train/plane ticket out of Thailand in order to get a Visa-on-Arrival? Trailing spaces on comment link format Properties of $x_k=\frac{a_{k+1}-a_{k}}{a_{k+1}}$ where $\{a_n\}$ is unbounded, strictly increasing sequence of positive reals Let $\{a_n\}$ be an unbounded, strictly increasing sequence of positive real numbers and let $x_k=\frac{a_{k+1}-a_{k}}{a_{k+1}}$. Which of the following statements is/are correct? (CSIR NET December 2014)         For all $n\geq m, \sum\limits^{n}_{k=m}x_k&gt;1-\bf{\frac{a_m}{a_n}}$   There exist $n\geq m, \sum\limits^{n}_{k=m}x_k&gt;\frac{1}{2}$      My attempt:  Analysing question in light of $a_k=k\implies x_k=\frac{k+1-k}{k+1}=\frac1{k+1}$, I feel both are correct, I doubt if  I can generalise the result in light of this one example.   Any way to prove that this true for general case?    Note: Please do not confuse  with my question. The first two options are different, I've marked the difference in bold. Help with this trigonometry problem Prove the given identity.  $$\left(\sin\frac {9\pi}{70}+ \sin\frac {29\pi}{70} - \sin\frac {31\pi}{70}\right) \left(\sin\frac {\pi}{70}-\sin\frac {11\pi}{70} - \sin\frac {19\pi}{70}\right) =\frac {\sqrt {5} -4}{4}$$  Please help, I could not gather enough ideas, even on how to get to the first step. I thought of using the transformation formula (from sum to product) but did not find a fruitful result.   UPDATE 1.:  $\left(-\frac{1 +\sqrt{5}}{8} + \frac{1}{8} \sqrt{14\left(5 - \sqrt{5} \right)}\right)\left(-\frac{ 1+ \sqrt{5}}{8} -\frac{1}{8} \sqrt{14 \left(5 -\sqrt{5} \right)}\right) $,    I noticed that Alexis had got to this point.  Can anyone explain me how did he get here, with calculations. Please help.  Thanks in Advance. The "proper" way to test if a service is running in a script My problem:  I'm writing a bash script and in it I'd like to check if a given service is running.  I know how to do this manually, with $ service [service_name] status.  But (especially since the move to systemd) that prints a whole bunch of text that's a little messy to parse. I assumed there's a command made for scripts with simple output or a return value I can check.  But Googling around only yields a ton of "Oh, just ps aux | grep -v grep | grep [service_name]" results. That can't be the best practice, is it? What if another instance of that command is running, but not one started by the SysV init script?  Or should I just shut up and get my hands dirty with a little pgrep? Solve this integral for free WiFi I saw this today, I checked in Mathematica and the integral comes out to $\pi$, but I have no idea how to solve it.     FREE Wi-Fi: The Wi-Fi password is the first $10$ digits of the answer.   $$\int_{-2}^2\left(x^3\cos\frac x2+\frac12\right)\sqrt{4-x^2}\ dx$$ How do you give a C# auto-property an initial value?  I either use the constructor, or revert to the old syntax.    Using the Constructor:  class Person  {     public Person()     {         Name = "Initial Name";     }     public string Name { get; set; } }   Using normal property syntax  (with an initial value)  private string name = "Initial Name"; public string Name  {     get      {         return name;     }     set     {         name = value;     } }   Is there a better way? Let  $$0 \rightarrow M \rightarrow N \rightarrow P \rightarrow 0$$  be an exact sequence of $A$-modules, where $A$ is a commutative ring with unity.  Then for each natural number $i$ one can look at the induced maps  $$\mathrm{Sym}^i(N) \rightarrow \mathrm{Sym}^i(P)$$  and   $$\mathrm{Sym}^i(M) \rightarrow \mathrm{Sym}^i(N).$$  The first question is, if they are still surjective, resp. injective, i.e. is $\mathrm{Sym}^i$ an exact functor?  The second question is: what are the kernel, resp. cokernel of these maps? I have a char in c#:  char foo = '2';   Now I want to get the 2 into an int.  I find that Convert.ToInt32 returns the actual decimal value of the char and not the number 2.  The following will work:  int bar = Convert.ToInt32(new string(foo, 1));   int.parse only works on strings as well.    Is there no native function in C# to go from a char to int without making it a string?  I know this is trivial but it just seems odd that there's nothing native to directly make the conversion. The sum of powers of two and two's complement – is there a deeper meaning behind this? For any prime $p > 3$, why is $p^2-1$ always divisible by 24? Here is my attempt to prove the Well-Ordering Principle, i.e. that any non-empty subset of $\Bbb N$, the set of natural numbers, has a minimum element.  Proof. Suppose there exists a non-empty subset $S$ of $\Bbb N$ such that $S$ has NO minimum element. Define $A = \left\{n\in \Bbb N : (\forall s\in S)(n \leq s)\right\}$. It is obvious that $1\in A$. Suppose $n\in A$, then for each $s \in S$, there exists $q \in N$ such that $n + q = s$. Since $q \ge 1$, $n+1 \leq s$, for all $s\in S$. By Principle of mathematical induction, $A = \Bbb N$. Take any $s_0 ∈ S$, then $(\forall s\in S)(s_0 \leq s)$. (This contradicts that $S$ has no minimum element).  How do I prove the statement without invoking Mathematical Induction? Also, I read that the proof of Principle of Mathematical Induction makes use of Well-Ordering. Can it be proven independently of Well-Ordering too? Why am I seeing two JPG files instead of RAW + JPG with a Canon 1100D? Given a file L with one non-negative integer per line and text file F, what would be a fast way to keep only those lines in F, whose line number appears in file L?  Example:  $ cat L.txt 1 3  $ cat F.txt Hello World Hallo Welt Hola mundo  $ command-in-question -x L.txt F.txt Hello World Hola mundo   I'm looking for a command that can handle a file L with 500 million or more entries; file L is sorted numerically.  Note: I'm halfway through an implementation for a command-in-question but I just wondered, whether one might be able to use some Unix tools here as well.    Update: Thank for all the answers, I learned a lot today! I would like to accept more one answer, but that's not possible. Ping is a a program owned by root with the user id bit set.  $ ls -l `which ping` -rwsr-xr-x 1 root root 35752 Nov  4  2011 /bin/ping   As I understand it, if a user runs the ping process, then the effective user id will change from the real user id (i.e. the user id of the person who launched the process) to the user id root. However when I try this and look at the output of ps to see if the ping process is running as the root user, I still get the real user id showing.  ps -e -o user,ruser,euser,cmd,args | grep ping sashan   sashan   sashan   ping -i 10 -c 1000 www.goog ping -i 10 -c 1000 www.google.com