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
Empty file added src/collatzConjection,js
Empty file.
17 changes: 17 additions & 0 deletions src/collatzConjection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

let arr = []
export default function collatzConjecture(num){
if(num === 1){
arr.push(1)
return arr
}
if(num % 2 === 0){
arr.push(num)
num = num / 2
return collatzConjecture(num)
}else if(num % 2 !== 0){
arr.push(num)
num = num * 3 + 1
return collatzConjecture(num)
}
}
17 changes: 17 additions & 0 deletions src/collatzConjecture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

let arr = []
export default function collatzConjecture(num){
if(num === 1){
arr.push(1)
return arr
}
if(num % 2 === 0){
arr.push(num)
num = num / 2
return collatzConjecture(num)
}else if(num % 2 !== 0){
arr.push(num)
num = num * 3 + 1
return collatzConjecture(num)
}
}
128 changes: 128 additions & 0 deletions src/comment from make_change.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*const useQaurter = function(amountGiven, price) {
amountGiven = amountGiven - 25
coins.qaurters++
return amountGiven

//console.log(amountGiven)
}




const useDime = function(amountGiven, price) {
amountGiven = amountGiven - 10
coins.dimes++
return amountGiven

//console.log(amountGiven)
}



const useNickel = function(amountGiven, price) {
amountGiven = amountGiven - 5
coins.nickels++
return amountGiven

//console.log(amountGiven)
}



const usePenny = function(amountGiven, price) {
amountGiven = amountGiven - 1
coins.pennies++
return amountGiven

//console.log(amountGiven)
}

function makeChange({price, amountGiven}) {
let results = {}
if(price === amountGiven) {

results.quarters = coins.quarters
results.dimes = coins.dimes
results.nickels = coins.nickels
results.pennies = coins.pennies

coins.quarters = 0
coins.dimes = 0
coins.nickels = 0
coins.pennies = 0


}

if( difference >= 25 ) {
amountGiven = takeQuarter(amountGiven, coins)
return makeChange({price: price, amountGiven: amountGiven})
}else if( difference >= 10) {
amountGiven = takeDime(amountGiven, price)
return makeChange({price: price, amountGiven: amountGiven})
}else if(difference >= 5){
amountGiven = takeNickel(amountGiven, price)
return makeChange({price: price, amountGiven: amountGiven})
}else if(difference >= 1){
amountGiven = takePenny(amountGiven, price)
return makeChange({price: price, amountGiven: amountGiven})
}
}
this worked

function makeChange({price, amountGiven}) {

const coins = {
// quarters: 0,
// dimes: 0,
// nickels: 0,
pennies: 0,
}

let difference = amountGiven - price

coins.pennies = difference
return coins

}

export default function makeChange({price, amountGiven}) {

const coins = {
quarters: 0,
dimes: 0,
nickels: 0,
pennies: 0,
}

let difference = amountGiven - price

let quarterValue = 25,
let dimeValue = 10,
let pennyValue = 1,
let nickelValue = 5,


let numberOfNickels = Math.floor(difference / nickelValue )
let numberOfPennies = Math.floor(difference / pennyValue )
let numberOfDimes = Math.floor(difference / dimeValue )
let numberOfQuarters = Math.floor(difference / quarterValue )



let numberOfPennies = difference
let numberOfNickels = difference
let numberOfDimes = difference
let numberOfQuarters = difference


coins.nickels = numberOfNickels
coins.pennies = numberOfPennies
coins.dimes = numberOfDimes
coins.quarters = numberOfQuarters



return coins

}
53 changes: 52 additions & 1 deletion src/makeChange.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
const coins = {
quarters: 0,
dimes: 0,
nickels: 0,
pennies: 0
}
const takeQuarter = function(amountGiven, price){
amountGiven = amountGiven - 25
coins.quarters++
return amountGiven
}
const takeDime = function(amountGiven, price){
amountGiven = amountGiven - 10
coins.dimes++
return amountGiven
}
const takeNickel = function(amountGiven, price){
amountGiven = amountGiven - 5
coins.nickels++
return amountGiven
}
const takePenny = function(amountGiven, price){
amountGiven = amountGiven - 1
coins.pennies++
return amountGiven
}
export default function makeChange({price, amountGiven}) {
// your code here
let results = {}
if(price === amountGiven) {
results.quarters = coins.quarters
results.dimes = coins.dimes
results.nickels = coins.nickels
results.pennies = coins.pennies

coins.quarters = 0
coins.dimes = 0
coins.nickels = 0
coins.pennies = 0
return results
}
if(amountGiven - price >= 25){
amountGiven = takeQuarter(amountGiven, coins)
return makeChange({price: price, amountGiven: amountGiven})
}else if(amountGiven - price >= 10){
amountGiven = takeDime(amountGiven, price)
return makeChange({price: price, amountGiven: amountGiven})
}else if(amountGiven - price >= 5){
amountGiven = takeNickel(amountGiven, price)
return makeChange({price: price, amountGiven: amountGiven})
}else if(amountGiven - price >= 1){
amountGiven = takePenny(amountGiven, price)
return makeChange({price: price, amountGiven: amountGiven})
}
}
15 changes: 15 additions & 0 deletions test/collatzConjection_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect } from 'chai'
import collatzConjecture from '../src/collatzConjecture'

describe('collatzConjecture()', function(){

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

it('take a number a perform an evaluation based on what the current number is then returns an array', function(){
expect(collatzConjecture(7)).to.eql([7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1])
expect(collatzConjecture(12)).to.eql([ 7,22,11,34,17,52,26,13,40,20,10,
5,16,8,4,2,1,12,6,3,10,5,16,8,4,2,1])
})
})
15 changes: 15 additions & 0 deletions test/collatzConjecture_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect } from 'chai'
import collatzConjecture from '../src/collatzConjecture'

describe('collatzConjecture()', function(){

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

it('take a number a perform an evaluation based on what the current number is then returns an array', function(){
expect(collatzConjecture(7)).to.eql([7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1])
expect(collatzConjecture(12)).to.eql([ 7,22,11,34,17,52,26,13,40,20,10,
5,16,8,4,2,1,12,6,3,10,5,16,8,4,2,1])
})
})