Skip to content
Open

Done #95

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions arrays.js
Original file line number Diff line number Diff line change
@@ -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");



259 changes: 130 additions & 129 deletions test/arrays-test.js
Original file line number Diff line number Diff line change
@@ -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]);
})
})
*/
})