Skip to content

Juan ordonez #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
35 changes: 34 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
*/
function trimProperties(obj) {
// ✨ implement

for (let key in obj) {
obj[key] = obj[key].trim();
}

return obj

}

/**
Expand All @@ -20,6 +27,12 @@ function trimProperties(obj) {
*/
function trimPropertiesMutation(obj) {
// ✨ implement
for (let key in obj) {
obj[key] = obj[key].trim();
}

return obj

}

/**
Expand All @@ -32,6 +45,17 @@ function trimPropertiesMutation(obj) {
*/
function findLargestInteger(integers) {
// ✨ implement
const arr = integers.map(el =>
el.integer
)
let largest = arr[0];

for (let x = 0; x <= largest; x++) {
if (arr[x] > largest) {
largest = arr[x];
}
}
return largest
}

class Counter {
Expand All @@ -41,6 +65,7 @@ class Counter {
*/
constructor(initialNumber) {
// ✨ initialize whatever properties are needed
this.count = initialNumber
}

/**
Expand All @@ -57,15 +82,22 @@ class Counter {
*/
countDown() {
// ✨ implement
return this.count > 0 ? this.count-- : 0;
// if (initialNumber > 0) {
// return initialNumber -= 1
// }
// }
}
}

class Seasons {
/**
* [Exercise 5A] Seasons creates a seasons object
*/
constructor() {
constructor(summer, fall, winter, spring) {
// ✨ initialize whatever properties are needed
this.seasons = ['winter', 'notspring', 'summer', 'fall']
this.currentSeason = 0
}

/**
Expand All @@ -82,6 +114,7 @@ class Seasons {
*/
next() {
// ✨ implement

}
}

Expand Down
91 changes: 59 additions & 32 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,80 @@ describe('[Exercise 1] trimProperties', () => {
const actual = utils.trimProperties(input)
expect(actual).toEqual(expected)
})
// test('[2] returns a copy, leaving the original object intact', () => {})
test('[2] returns a copy, leaving the original object intact', () => {
const input = { foo: ' foo ', bar: 'bar ', baz: ' baz' }
const copy = utils.trimProperties(input)
expect(copy).toBeDefined()
expect(input).toEqual(input)
})
})

describe('[Exercise 2] trimPropertiesMutation', () => {
// test('[3] returns an object with the properties trimmed', () => {})
// test('[4] the object returned is the exact same one we passed in', () => {})
test('[3] returns an object with the properties trimmed', () => {
const input = { foo: ' foo ' }
const actual = utils.trimPropertiesMutation(input)
const expected = { foo: 'foo' }
expect(expected).toEqual(actual)
})
test('[4] the object returned is the exact same one we passed in', () => {
const input = { foo: ' foo ', bar: 'bar ', baz: ' baz' }
const trimmed = utils.trimProperties(input)
expect(input).toBe(trimmed)
})
})

describe('[Exercise 3] findLargestInteger', () => {
// test('[5] returns the largest number in an array of objects { integer: 2 }', () => {})
test('[5] returns the largest number in an array of objects { integer: 2 }', () => {
const input = [{ integer: 1 }, { integer: 2 }, { integer: 3 }]
const invoked = utils.findLargestInteger(input)
expect(invoked).toBe(3)
})
})

describe('[Exercise 4] Counter', () => {
let counter
let counter;
beforeEach(() => {
counter = new utils.Counter(3) // each test must start with a fresh couter
counter = new utils.Counter(3) // each test must start with a fresh counter
// counter = new utils.Counter(4)
})
// test('[6] the FIRST CALL of counter.countDown returns the initial count', () => {})
// test('[7] the SECOND CALL of counter.countDown returns the initial count minus one', () => {})
// test('[8] the count eventually reaches zero but does not go below zero', () => {})
})
test('[6] the FIRST CALL of counter.countDown returns the initial count', () => {
expect(counter.countDown()).toBe(3)

describe('[Exercise 5] Seasons', () => {
let seasons
beforeEach(() => {
seasons = new utils.Seasons() // each test must start with fresh seasons
})
// test('[9] the FIRST call of seasons.next returns "summer"', () => {})
// test('[10] the SECOND call of seasons.next returns "fall"', () => {})
// test('[11] the THIRD call of seasons.next returns "winter"', () => {})
// test('[12] the FOURTH call of seasons.next returns "spring"', () => {})
// test('[13] the FIFTH call of seasons.next returns again "summer"', () => {})
// test('[14] the 40th call of seasons.next returns "spring"', () => {})
})

describe('[Exercise 6] Car', () => {
let focus
beforeEach(() => {
focus = new utils.Car('focus', 20, 30) // each test must start with a fresh car
})
// test('[15] driving the car returns the updated odometer', () => {})
// test('[16] driving the car uses gas', () => {})
// test('[17] refueling allows to keep driving', () => {})
// test('[18] adding fuel to a full tank has no effect', () => {})
test('[7] the SECOND CALL of counter.countDown returns the initial count minus one', () => {
counter.countDown()
expect(counter.count).toEqual(2)
})
test('[8] the count eventually reaches zero but does not go below zero', () => {
expect(counter.count).toBeGreaterThan(0)
})
})

// describe('[Exercise 5] Seasons', () => {
// let seasons
// beforeEach(() => {
// seasons = new utils.Seasons() // each test must start with fresh seasons
// })
// // test('[9] the FIRST call of seasons.next returns "summer"', () => {})
// // test('[10] the SECOND call of seasons.next returns "fall"', () => {})
// // test('[11] the THIRD call of seasons.next returns "winter"', () => {})
// // test('[12] the FOURTH call of seasons.next returns "spring"', () => {})
// // test('[13] the FIFTH call of seasons.next returns again "summer"', () => {})
// // test('[14] the 40th call of seasons.next returns "spring"', () => {})
// })

// describe('[Exercise 6] Car', () => {
// let focus
// beforeEach(() => {
// focus = new utils.Car('focus', 20, 30) // each test must start with a fresh car
// })
// // test('[15] driving the car returns the updated odometer', () => {})
// // test('[16] driving the car uses gas', () => {})
// // test('[17] refueling allows to keep driving', () => {})
// // test('[18] adding fuel to a full tank has no effect', () => {})
// })

describe('[Exercise 7] isEvenNumberAsync', () => {
// test('[19] resolves true if passed an even number', () => {})
test('[19] resolves true if passed an even number', () => { })
// test('[20] resolves false if passed an odd number', () => {})
})
Loading