Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

I'm trying to pass this test I was given, but I haven't gotten pretty far.

describe('closures pt.2', () => { it(take an array and return an object with three functions: * pluck: Takes a key name and returns an array of the value matching that key for each item in the array. * inc: Takes an integer and updates the "count" value for each item in the array by adding the argument to the current count. * get: Takes a string and returns the item in the array whose name matches the string. , () => { const arr = [ { name: 'foo', count: 1 }, { name: 'bar', count: 3 }, { name: 'baz', count: 0 } ];

  const wrappedArray = wrapArr(arr);

  expect(wrappedArray.pluck('name')).toEqual(['foo', 'bar', 'baz']);
  expect(wrappedArray.pluck('count')).toEqual([1, 3, 0]);
  wrappedArray.inc(3);
  expect(wrappedArray.pluck('count')).toEqual([4, 6, 3]);
  expect(wrappedArray.get('bar')).toEqual({ name: 'bar', count: 4 });
});

});

1 Answer

describe('closures pt.2', () => {
    it(`take an array and return an object with three functions:
        * pluck: Takes a key name and returns an array of the value matching that key for each item in the array.
        * inc: Takes an integer and updates the "count" value for each item in the array by adding the argument to the current count.
        * get: Takes a string and returns the item in the array whose name matches the string.
      `, () => {
      const arr = [
        {
          name: 'foo',
          count: 1
        },
        {
          name: 'bar',
          count: 3
        },
        {
          name: 'baz',
          count: 0
        }
      ];

      const wrappedArray = wrapArr(arr);

      expect(wrappedArray.pluck('name')).toEqual(['foo', 'bar', 'baz']);
      expect(wrappedArray.pluck('count')).toEqual([1, 3, 0]);
      wrappedArray.inc(3);
      expect(wrappedArray.pluck('count')).toEqual([4, 6, 3]);
      expect(wrappedArray.get('bar')).toEqual({ name: 'bar', count: 4 });
    });
  });