This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let indexOf = (array, value) => { | |
let compareArray = array | |
for(let i = 0; i < compareArray.length; i++) { | |
if(value === compareArray[i]) { | |
return i | |
} | |
} | |
return -1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let expect = require ('chai').expect | |
let indexOf = require ('../src/indexOf') | |
describe('indexOf()', () => { | |
it('Gets the index at which the first occurrence of value is found in array', () => { | |
expect(indexOf([1, 2, 3, 4, 5], 5)).to.deep.equal(4) | |
expect(indexOf(['1', '2', '3', '4', '5'], '5')).to.deep.equal(4) | |
expect(indexOf([1, 2, 3, 4, 5], 7)).to.deep.equal(-1) | |
expect(indexOf([1, 2, 3, 4, 5], -3)).to.deep.equal(-1) | |
expect(indexOf([1, 2, 3, 4, 5], '3')).to.deep.equal(-1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*adds two numbers | |
*/ | |
const add = (x,y) => x + y | |
module.exports = add | |
// Before refactoring: | |
// var result = x + y | |
// return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let expect = require ('chai').expect | |
let add = require ('../src/add') | |
describe('add()', () => { | |
it('adds two numbers', () => { | |
expect(add(4,6)).to.deep.equal(10) | |
expect(add(-10,5)).to.deep.equal(-5) | |
expect(add(0,0)).to.deep.equal(0) | |
expect(add(-2,-3)).to.deep.equal(-5) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*subtracts two numbers | |
*/ | |
const subtract = (x,y) => x - y | |
module.exports = subtract | |
// Before refactoring: | |
// let answer = x - y | |
// return answer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let expect = require ('chai').expect | |
let subtract = require ('../src/subtract') | |
describe('subtract()', () => { | |
it('subtract two numbers', () => { | |
expect(subtract(10, 5)).to.deep.equal(5) | |
expect(subtract(-10, 5)).to.deep.equal(-15) | |
expect(subtract(-10, -5)).to.deep.equal(-5) | |
expect(subtract(0,0)).to.deep.equal(0) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let slice = (array, start, end) => { | |
let origArray = array, | |
slicedArray = [] | |
for(let i = origArray[start-1]; i < end; i++) { | |
slicedArray.push(origArray[i]) | |
} | |
return slicedArray | |
} | |
module.exports = slice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let expect = require ('chai').expect | |
let slice = require ('../src/slice') | |
describe('slice()', () => { | |
it('Creates a slice of array from start up to but now including end', () => { | |
expect(slice(['1', '2', '3', '4', '5'], 1, 3)).to.deep.equal(['2','3']) | |
expect(slice([1, 2, 3, 4, 5], 1, 3)).to.deep.equal([2, 3]) | |
expect(slice([1, '2', [3], 4, 5], 1, 3)).to.deep.equal(['2', [3]]) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Node { | |
constructor(data){ | |
this.data = data | |
this.next = undefined | |
} | |
getData() { | |
// returns the data ("apple") of the node | |
return this.data | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import chai, { expect } from 'chai' | |
import chaiChange from 'chai-change' | |
import Node from '../src/node' | |
chai.use(chaiChange) | |
describe('Node', () => { | |
const nodeA = new Node({data: 'apple'}) | |
const nodeB = new Node({data: 'banana'}) |
OlderNewer