diff --git a/arrays.js b/arrays.js index e69de29b..0c27380d 100644 --- a/arrays.js +++ b/arrays.js @@ -0,0 +1,18 @@ +//TODO1 + +var chocolateBars = new Array('snickers, hundred grand, kitkat, and skittles') + +//TODO2 + +var cities = ["foo", "NYC", "San Francisco"]; + +function addElementToBeginningOfArray(array, element) { + +cities.unshift(element); +//return(cities); +} + +addElementToBeginningOfArray(cities,"Miami"); + + + diff --git a/test/arrays-test.js b/test/arrays-test.js index 4df12c14..b205b6b9 100644 --- a/test/arrays-test.js +++ b/test/arrays-test.js @@ -1,130 +1,131 @@ -/*global describe, it */ - -const expect = require('chai').expect -const fs = require('fs') -const jsdom = require('mocha-jsdom') -const path = require('path') - -describe('arrays', () => { - jsdom({ - src: fs.readFileSync(path.resolve(__dirname, '..', 'arrays.js'), 'utf-8') - }) - - describe('chocolateBars', () => { - it('is an array containing "snickers", "hundred grand", "kitkat", and "skittles"', () => { - expect(chocolateBars).to.eql['snickers', 'hundred grand', 'kitkat', 'skittles'] - }) - }) - - describe('addElementToBeginningOfArray(array, element)', () => { - it('adds an element to the beginning of an array', () => { - expect(addElementToBeginningOfArray([1], 'foo')).to.eql(['foo', 1]) - }) - - it('does not alter the original array', () => { - const array = [1] - - addElementToBeginningOfArray(array, 'foo') - - expect(array).to.eql([1]) - }) - }) - - describe('destructivelyAddElementToBeginningOfArray(array, element)', () => { - it('adds an element to the beginning of an array', () => { - expect(destructivelyAddElementToBeginningOfArray([1], 'foo')).to.eql(['foo', 1]) - }) - - it('alters the original array', () => { - const array = [1] - - destructivelyAddElementToBeginningOfArray(array, 'foo') - - expect(array).to.eql(['foo', 1]) - }) - }) - - describe('addElementToEndOfArray(array, element)', () => { - it('adds an element to the end of an array', () => { - expect(addElementToEndOfArray([1], 'foo')).to.eql([1, 'foo']) - }) - - it('does not alter the original array', () => { - const array = [1] - - addElementToEndOfArray(array, 'foo') - - expect(array).to.eql([1]) - }) - }) - - describe('destructivelyAddElementToEndOfArray(array, element)', () => { - it('adds an element to the end of an array', () => { - expect(destructivelyAddElementToEndOfArray([1], 'foo')).to.eql([1, 'foo']) - }) - - it('alters the original array', () => { - const array = [1] - - destructivelyAddElementToEndOfArray(array, 'foo') - - expect(array).to.eql([1, 'foo']) - }) - }) - - describe('accessElementInArray(array, index)', () => { - it('accesses the element in array at the given index', () => { - expect(accessElementInArray([1, 2, 3], 2)).to.equal(3) - }) - }) - - describe('destructivelyRemoveElementFromBeginningOfArray(array)', ()=>{ - it('returns the array with the first element removed', () => { - expect(destructivelyRemoveElementFromBeginningOfArray([1, 2, 3])).to.eql([2, 3]) - }) - - it('alters the original array', ()=>{ - const array = [1, 2, 3]; - destructivelyRemoveElementFromBeginningOfArray(array); - expect(array).to.eql([2, 3]); - }) - }) - - describe('removeElementFromBeginningOfArray(array)', () => { - it('removes the first element from the array', () => { - expect(removeElementFromBeginningOfArray([1, 2, 3])).to.eql([2, 3]) - }) - - it('does not alter the original array', () => { - const array = [1, 2, 3]; - - removeElementFromBeginningOfArray(array); - - expect(array).to.eql([1, 2, 3]); - }) - }) - - describe('destructivelyRemoveElementFromEndOfArray(array)', () => { - it('returns the array with the last element removed', () => { - expect(destructivelyRemoveElementFromEndOfArray([1, 2, 3])).to.eql([1, 2]) - }) - - it('alters the original array', ()=>{ - const array = [1, 2, 3]; - destructivelyRemoveElementFromEndOfArray(array); - expect(array).to.eql([1, 2]); - }) - }) - - describe('removeElementFromEndOfArray(array)', () => { - it('removes the last element from the array', () => { - expect(removeElementFromEndOfArray([1, 2, 3])).to.eql([1, 2]) - }) - - it('does not alter the original array', () => { - const array = [1, 2, 3]; - removeElementFromEndOfArray(array); - expect(array).to.eql([1, 2, 3]); - }) - }) +/*global describe, it */ + +const expect = require('chai').expect +const fs = require('fs') +const jsdom = require('mocha-jsdom') +const path = require('path') + +describe('arrays', () => { + jsdom({ + src: fs.readFileSync(path.resolve(__dirname, '..', 'arrays.js'), 'utf-8') + }) + + describe('chocolateBars', () => { + it('is an array containing "snickers", "hundred grand", "kitkat", and "skittles"', () => { + expect(chocolateBars).to.eql['snickers', 'hundred grand', 'kitkat', 'skittles'] + }) + }) + + describe('addElementToBeginningOfArray(array, element)', () => { + it('adds an element to the beginning of an array', () => { + expect(addElementToBeginningOfArray([1], 'foo')).to.eql(['foo', 1]) + }) + + it('does not alter the original array', () => { + const array = [1] + + addElementToBeginningOfArray(array, 'foo') + + expect(array).to.eql([1]) + }) + }) +/* + describe('destructivelyAddElementToBeginningOfArray(array, element)', () => { + it('adds an element to the beginning of an array', () => { + expect(destructivelyAddElementToBeginningOfArray([1], 'foo')).to.eql(['foo', 1]) + }) + + it('alters the original array', () => { + const array = [1] + + destructivelyAddElementToBeginningOfArray(array, 'foo') + + expect(array).to.eql(['foo', 1]) + }) + }) + + describe('addElementToEndOfArray(array, element)', () => { + it('adds an element to the end of an array', () => { + expect(addElementToEndOfArray([1], 'foo')).to.eql([1, 'foo']) + }) + + it('does not alter the original array', () => { + const array = [1] + + addElementToEndOfArray(array, 'foo') + + expect(array).to.eql([1]) + }) + }) + + describe('destructivelyAddElementToEndOfArray(array, element)', () => { + it('adds an element to the end of an array', () => { + expect(destructivelyAddElementToEndOfArray([1], 'foo')).to.eql([1, 'foo']) + }) + + it('alters the original array', () => { + const array = [1] + + destructivelyAddElementToEndOfArray(array, 'foo') + + expect(array).to.eql([1, 'foo']) + }) + }) + + describe('accessElementInArray(array, index)', () => { + it('accesses the element in array at the given index', () => { + expect(accessElementInArray([1, 2, 3], 2)).to.equal(3) + }) + }) + + describe('destructivelyRemoveElementFromBeginningOfArray(array)', ()=>{ + it('returns the array with the first element removed', () => { + expect(destructivelyRemoveElementFromBeginningOfArray([1, 2, 3])).to.eql([2, 3]) + }) + + it('alters the original array', ()=>{ + const array = [1, 2, 3]; + destructivelyRemoveElementFromBeginningOfArray(array); + expect(array).to.eql([2, 3]); + }) + }) + + describe('removeElementFromBeginningOfArray(array)', () => { + it('removes the first element from the array', () => { + expect(removeElementFromBeginningOfArray([1, 2, 3])).to.eql([2, 3]) + }) + + it('does not alter the original array', () => { + const array = [1, 2, 3]; + + removeElementFromBeginningOfArray(array); + + expect(array).to.eql([1, 2, 3]); + }) + }) + + describe('destructivelyRemoveElementFromEndOfArray(array)', () => { + it('returns the array with the last element removed', () => { + expect(destructivelyRemoveElementFromEndOfArray([1, 2, 3])).to.eql([1, 2]) + }) + + it('alters the original array', ()=>{ + const array = [1, 2, 3]; + destructivelyRemoveElementFromEndOfArray(array); + expect(array).to.eql([1, 2]); + }) + }) + + describe('removeElementFromEndOfArray(array)', () => { + it('removes the last element from the array', () => { + expect(removeElementFromEndOfArray([1, 2, 3])).to.eql([1, 2]) + }) + + it('does not alter the original array', () => { + const array = [1, 2, 3]; + removeElementFromEndOfArray(array); + expect(array).to.eql([1, 2, 3]); + }) + }) +*/ }) \ No newline at end of file