Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

330
Views
Java Script Function changes parameter variables globally, how to avoid that?

rotr() removes the last array value and places it to array-index 0 (to the the beginning). The method does that for n times. Its rotating the array x by n.

My problem is the first XORXOR parameter is w[sh1] rotatet by 7. Okay! Thats good.

The second XORXOR parameter is rotatet by 7 + 18 and the last parameter is rotatet by 7+18+3. Thats not how i want it...

The first parameter of rotr should and must always be the same array. Why is the function changing the array globally. Its not modifying the parameter and returns a copy of that modification? With return? Always used Python... then one time a little bit JS and its completely getting on my nerves... can someone help me and explain it to me?? my whole algorithm is a failure because of that *****

const s0 = XORXOR(rotr(w[sh1], 7), rotr(w[sh1], 18), shr(w[sh1], 3))

function rotr(x, n) {
    for(let c = 0; c<n; c++) {
        x.unshift(x.pop());
    }
    return x
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the spread operator (...)

const s0 = [1, 2, 3, 4];

function rotr(x, n) {
  const copy = [...x];
  for (let c = 0; c < n; c++)
    copy.unshift(copy.pop());

  console.log(`original array: ${x} and changed array: ${copy}`)
  return copy
}

rotr(s0, 2)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!