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

389
Views
How do I use the spread operator in this function?

This is on my index.js file in VSC

describe('appendCat(name)', function () {
  it('appends a cat to the cats array and returns a new array, leaving the cats array unchanged', function () {
    expect(appendCat("Broom")).to.have.ordered.members(["Milo", "Otis", "Garfield", "Broom"]);

    expect(cats).to.have.ordered.members(["Milo", "Otis", "Garfield"]);
  });
});

I am supposed to append a cat to the cats array leaving the cats array unchanged.

I have no idea how to write the function for this

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You mean something like this?

This will spread the cats array, plus add a new element to it named "Broom", but the initial cats array will not be changed.

describe('appendCat(name)', function () {
  it('appends a cat to the cats array and returns a new array, leaving the cats array unchanged', function () {
    expect(appendCat("Broom")).to.have.ordered.members([...cats, "Broom"]);

    expect(cats).to.have.ordered.members(["Milo", "Otis", "Garfield"]);
  });
});
about 4 years ago · Juan Pablo Isaza Report

0

You can do like this

[...cats, "name of cat"]
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!