Skip to content

first commit #41

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 3 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
6 changes: 3 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true,
"node": true,
"jest": true
"jest":true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest"
"ecmaVersion": 13
},
"rules": {
}
Expand Down
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
* trimProperties({ name: ' jane ' }) // returns a new object { name: 'jane' }
*/
function trimProperties(obj) {
// ✨ implement
for (let i in obj) {
obj[i] = obj[i].trim()
}
return obj
}

/**
Expand All @@ -19,7 +22,10 @@ function trimProperties(obj) {
* trimPropertiesMutation({ name: ' jane ' }) // returns the object mutated in place { name: 'jane' }
*/
function trimPropertiesMutation(obj) {
// ✨ implement
for (let i in obj) {
obj[i] = obj[i].trim()
}
return obj
}

/**
Expand All @@ -31,7 +37,12 @@ function trimPropertiesMutation(obj) {
* findLargestInteger([{ integer: 1 }, { integer: 3 }, { integer: 2 }]) // returns 3
*/
function findLargestInteger(integers) {
// ✨ implement
let largest = 0
for (let i = 0; i < integers.length; i++){
if (integers[i].integer > largest) {
largest = integers[i].integer
}
}return largest
}

class Counter {
Expand Down
93 changes: 55 additions & 38 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,70 @@ 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 mutation = utils.trimProperties(input)
expect(mutation).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 ', bar: 'bar ', baz: ' baz' }
const trimmed = utils.trimProperties(input)
expect(trimmed).toBeDefined()
expect(input).toEqual(input)
})
test('[4] the object returned is the exact same one we passed in', () => {
const input = { foo: ' foo ', bar: 'bar ', baz: ' baz' }
expect(input).toEqual(input)
})
})

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

describe('[Exercise 4] Counter', () => {
let counter
beforeEach(() => {
counter = new utils.Counter(3) // each test must start with a fresh couter
expect (utils.findLargestInteger(integers)).toBe(3)
})
// 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', () => {})
})

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 4] Counter', () => {
// let counter
// beforeEach(() => {
// counter = new utils.Counter(3) // each test must start with a fresh couter
// })
// // 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', () => {})
// })

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 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 7] isEvenNumberAsync', () => {
// test('[19] resolves true if passed an even number', () => {})
// test('[20] resolves false if passed an odd number', () => {})
})
// 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('[20] resolves false if passed an odd number', () => {})
// })
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ module.exports = {
// bail: 0,

// The directory where Jest should store its cached dependency information
// cacheDirectory: "/private/var/folders/mq/wc13nlwj4gdgcyshdy5j1hgr0000gn/T/jest_dx",
// cacheDirectory: "/private/var/folders/27/bl_jm__s68n13g73b_xg0vtm0000gn/T/jest_dx",

// Automatically clear mock calls and instances between every test
// Automatically clear mock calls, instances and results before every test
// clearMocks: false,

// Indicates whether the coverage information should be collected while executing the test
Expand Down Expand Up @@ -101,7 +101,7 @@ module.exports = {
// Use this configuration option to add custom reporters to Jest
// reporters: undefined,

// Automatically reset mock state between every test
// Automatically reset mock state before every test
// resetMocks: false,

// Reset the module registry before running each individual test
Expand All @@ -110,7 +110,7 @@ module.exports = {
// A path to a custom resolver
// resolver: undefined,

// Automatically restore mock state between every test
// Automatically restore mock state and implementation before every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within
Expand Down
Loading