Question: Please implement the function below in Javascript and name the source file as h2.js . A test file h2.test.js is provided below! You need to

Please implement the function below in Javascript and name the source file as h2.js. A test file h2.test.js is provided below! You need to install the jest before testing your code.

h2.test.js

const { change, stripQuotes, scramble, say, powers, interleave, } = require('./h2'); // Helper for the scramble tests function anagramsOfEachOther(s, t) { return s.split('').sort().join('') === t.split('').sort().join(''); } // Helper for testing the callbacky problems function generatorToArray(generator, ...args) { const result = []; generator(...args, (item) => result.push(item)); return result; } describe('change', () => { it('handles zero', () => { expect(change(0)).toEqual([0, 0, 0, 0]); }); it('computes answers for small integer values fine', () => { expect(change(97)).toEqual([3, 2, 0, 2]); expect(change(8)).toEqual([0, 0, 1, 3]); expect(change(250)).toEqual([10, 0, 0, 0]); expect(change(144)).toEqual([5, 1, 1, 4]); expect(change(97)).toEqual([3, 2, 0, 2]); }); it('handles large values', () => { // This test only passes if the solution is efficient expect(change(100000000000)).toEqual([4000000000, 0, 0, 0]); }); it('throws the proper exception for negative arguments', () => { expect(() => change(-50)).toThrow(RangeError); }); }); describe('stripQuotes', () => { it('works on the empty string', () => { expect(stripQuotes('')).toEqual(''); }); it('strips quotes properly for non-empty strings', () => { expect(stripQuotes('Hello, world')).toEqual('Hello, world'); expect(stripQuotes('"\'')).toEqual(''); expect(stripQuotes('a"""\'\'"z')).toEqual('az'); }); }); describe('scramble', () => { it('scrambles properly', () => { ['a', 'rat', 'JavaScript testing', '', 'zzz', '^*^*)^'].forEach((s) => { expect(anagramsOfEachOther(s, scramble(s))).toBeTruthy(); }); }); it('is really random (produces all permutations)', () => { const possibilities = new Set('ABC ACB BAC BCA CAB CBA'.split(' ')); for (let i = 0; i  { it('works when there are no words', () => { expect(say()).toBe(''); }); it('works when there are words', () => { expect(say('hi')()).toBe('hi'); expect(say('hi')('there')()).toBe('hi there'); expect(say('hello')('my')('name')('is')('Colette')()).toBe('hello my name is Colette'); }); }); describe('powers', () => { it('generates sequences of powers properly', () => { expect(generatorToArray(powers, 2, -5)).toEqual([]); expect(generatorToArray(powers, 7, 0)).toEqual([]); expect(generatorToArray(powers, 3, 1)).toEqual([1]); expect(generatorToArray(powers, 2, 63)).toEqual([1, 2, 4, 8, 16, 32]); expect(generatorToArray(powers, 2, 64)).toEqual([1, 2, 4, 8, 16, 32, 64]); }); }); describe('interleave', () => { it('interleaves properly', () => { expect(interleave([])).toEqual([]); expect(interleave([1, 4, 6])).toEqual([1, 4, 6]); expect(interleave([], 2, 3)).toEqual([2, 3]); expect(interleave([1], 9)).toEqual([1, 9]); expect(interleave([8, 8, 3, 9], 1)).toEqual([8, 1, 8, 3, 9]); expect(interleave([2], 7, '8', {})).toEqual([2, 7, '8', {}]); }); }); Please implement the function below in Javascript and name the source file

1. A function change() that accepts a number of U.S. cents and returns a tuple containing, respectively, the smallest number of U.S. quarters, dimes, nickels, and pennies that equal the given amount. > change (96) [ 3, 2, 0, 1 ] >>> change(8) [ 0, 0, 1, 3 ] > change (-4) RangeError: amount cannot be negative > change (33.25) [ 1, 0, 1, 3.25 ] 1. A function change() that accepts a number of U.S. cents and returns a tuple containing, respectively, the smallest number of U.S. quarters, dimes, nickels, and pennies that equal the given amount. > change (96) [ 3, 2, 0, 1 ] >>> change(8) [ 0, 0, 1, 3 ] > change (-4) RangeError: amount cannot be negative > change (33.25) [ 1, 0, 1, 3.25 ]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!