Skip to content
Open
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
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,25 @@ Base repository for the [Core Algorithms](http://jsdev.learnersguild.org/goals/1

## Installation and Setup

_Fill this out_
`npm i`

## Usage and Examples

_...and this_
`npm test` to run all tests

## Specs
completed: makeChange, fizzBuzz, isPalindrome, Factorial out of 10 function in ALGORITHMS.md for CLassic, Numeric, and Set (not done)

- [X] Artifact produced is a fork of the core-algorithms repo.
- [X] Can run all tests with npm test.
- [X] All tests are passing.
- [X] For each algorithm in the algorithms list, there exists:
- [X] a test file with at least 2 unit tests using valid inputs, and at least 1 unit test using invalid inputs.
an implementation file with a correct implementation of the algorithm.
- [X] Repository includes a README file with basic installation and setup instructions.
- [X] All dependencies are properly declared in package.json.
- [X] All major features are added via pull requests with a clear description and concise commit messages.
- [ ] Code uses a linter and there are no linting errors.
- [X] Variables, functions, files, etc. have appropriate and meaningful names.
- [X] Functions are small and serve a single purpose.
- [X] The artifact produced is properly licensed, preferably with the MIT license.
16 changes: 16 additions & 0 deletions src/factorial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const factorial = value => {

if( typeof value !== 'number' ){
return 'value is not a number'
}

let factorialNumber = 1
for(let index = 1; index <= value; index++){
factorialNumber *= index
}

return factorialNumber

}

export default factorial
19 changes: 19 additions & 0 deletions src/fizzBuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default function fizzBuzz(value) {
const returnArray = []
for (let index = 1; index <= value; index++) {
let fizzBuzzyValue = ''

if(i % 3 === 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i is not defined (I think you meant index)

fizzBuzzyValue = fizzBuzzyValue.concat('Fizz')
}
if(i % 5 === 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i is not defined (I think you meant index)

fizzBuzzyValue = fizzBuzzyValue.concat('Buzz')
}
if(fizzBuzzyValue === '') {
fizzBuzzyValue = index
}
returnArray.push(fizzBuzzyValue)
}

return returnArray
}
19 changes: 19 additions & 0 deletions src/isPalindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const isPalidrome = string => {

if ( typeof string !== 'string') {
return "This is not a string"
}

let reversedString = '',
originalOnlyLetters = string.replace(/[\W_]/g, '').toLowerCase()

for ( let index = string.length - 1; index >= 0; index-- ) {
if ( string[index].search(/[\W_]/g) === -1 ) {
reversedString += string[index]
}
}

return originalOnlyLetters === reversedString.toLowerCase()
}

export default isPalidrome
40 changes: 38 additions & 2 deletions src/makeChange.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
export default function makeChange({price, amountGiven}) {
// your code here
const makeChange = ({price, amountGiven}) => {
let moneyBack = amountGiven - price
if ( moneyBack === NaN ) {
return 'no money given'
}
if ( moneyBack < 0 ) {
return 'You need to give more money!!!'
}

let change = {
quarters: 0,
dimes: 0,
nickels: 0,
pennies: 0,
}

while ( moneyBack > 24 ) {
change.quarters++
moneyBack -= 25
}

while ( moneyBack > 9 ) {
change.dimes++
moneyBack -= 10
}

while ( moneyBack > 4 ) {
change.nickels++
moneyBack -= 5
}

while ( moneyBack > 0 ) {
change.pennies++
moneyBack -= 1
}
return change
}

export default makeChange
19 changes: 19 additions & 0 deletions test/factorial_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from 'chai'
import factorial from '../src/factorial'

describe('factorial()', () => {

it('should be a function', () => {
expect(factorial).to.be.a('function')
})

it('returns the factorial of a number', () => {
expect(factorial(7)).to.equal(5040)
expect(factorial(4)).to.equal(24)
expect(factorial(5)).to.equal(120)
})

it('only takes numbers', () => {
expect(factorial('blah blah')).to.equal('value is not a number')
})
})
26 changes: 26 additions & 0 deletions test/fizzBuzz_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect } from 'chai'
import fizzBuzz from '../src/fizzBuzz'

describe('fizzBuzz()', () => {

it('should be a function', () => {
expect(fizzBuzz).to.be.a('function')
})

it('returns an array of numbers from 1 to value given', () => {
const returnArray = fizzBuzz(87)
expect(returnArray.length).to.equal(87)
})

it('replaces mutiples of 3 with the string\'Fizz\', multiples of 5 with \'Buzz\', and multiples of 3 & 5 with \'FizzBuzz\'', () => {
const returnArray = fizzBuzz(64)

expect(returnArray[0]).to.eql(1)
expect(returnArray[2]).to.eql('Fizz')
expect(returnArray[5]).to.eql('Fizz')
expect(returnArray[4]).to.eql('Buzz')
expect(returnArray[14]).to.eql('FizzBuzz')
expect(returnArray[13]).to.eql(14)
expect(returnArray[29]).to.eql('FizzBuzz')
})
})
27 changes: 27 additions & 0 deletions test/isPalindrome_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect } from 'chai'
import isPalindrome from '../src/isPalindrome'

describe('isPalindrome()', function(){

it('should be a function', function(){
expect(isPalindrome).to.be.a('function')
})

it('Returns true if value given is a isPalindrome, false if not', () => {
expect(isPalindrome('ana')).to.be.true

expect(isPalindrome('beyonce')).to.be.false
})

it('Gets rid of punctiuation and white space to evaluate entire statement given', () => {
expect(isPalindrome('A man, a plan, a canal: Panama')).to.be.true

expect(isPalindrome('Hi my name is Ana!')).to.be.false
})

it('Only take strings', () => {
expect(isPalindrome(300)).to.equal('This is not a string')

expect(isPalindrome(null)).to.equal('This is not a string')
})
})
10 changes: 5 additions & 5 deletions test/makeChange_test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from 'chai'
import makeChange from '../src/makeChange'

describe('makeChange()', function(){
describe('makeChange()', () => {

it('should be a function', function(){
it('should be a function', () => {
expect(makeChange).to.be.a('function')
})

it('returns an object with all coin types (quarters, dimes, nickels, and pennies)', function(){
it('returns an object with all coin types (quarters, dimes, nickels, and pennies)', () => {
const change = makeChange({price: 100, amountGiven: 100})
expect(change).to.be.an('object')
expect(change).to.have.keys('quarters', 'dimes', 'nickels', 'pennies')
Expand All @@ -19,7 +19,7 @@ describe('makeChange()', function(){
})
})

it('returns correct change', function(){
it('returns correct change', () => {
expect(makeChange({price: 100, amountGiven: 141})).to.deep.equal({
quarters: 1,
dimes: 1,
Expand All @@ -28,7 +28,7 @@ describe('makeChange()', function(){
})
})

it('minimizes the number of coins given by using the most high-value coins', function(){
it('minimizes the number of coins given by using the most high-value coins', () => {
expect(makeChange({price: 100, amountGiven: 168})).to.deep.equal({
quarters: 2,
dimes: 1,
Expand Down