Skip to content
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

Yonathan admasu #23

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
another one
  • Loading branch information
Yonathan-Admasu728 committed Jul 14, 2021
commit 672533bf1cea7d13a2ac3c9865a99684ffaf806d
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ function trimProperties(obj) {
* trimPropertiesMutation({ name: ' jane ' }) // returns the object mutated in place { name: 'jane' }
*/
function trimPropertiesMutation(obj) {
// ✨ implement
for (let prop in obj) {
obj[prop]= obj[prop].trim()
}
return obj
}

/**
Expand All @@ -35,7 +38,13 @@ function trimPropertiesMutation(obj) {
* findLargestInteger([{ integer: 1 }, { integer: 3 }, { integer: 2 }]) // returns 3
*/
function findLargestInteger(integers) {
// ✨ implement
let result = integers[0].integer
for (let idx = 1; idx < integers.length; idx++) {
if (integers[idx].integer > result) {
result = integers[idx].integer
}
}
return result
}

class Counter {
Expand Down
25 changes: 22 additions & 3 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,31 @@ describe('[Exercise 1] trimProperties', () => {
})

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 expected = { foo: 'foo', bar: 'bar', baz: 'baz' }
const actual = utils.trimProperties(input)
expect(actual).toEqual(expected)
})
test('[4] the object returned is the exact same one we passed in', () => {
const input = { foo: ' foo ', bar: 'bar ', baz: ' baz' }
const actual = utils.trimPropertiesMutation(input)
expect(actual).toBe(input)
})
})

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: 3 }, { integer: 2 }]
const input2 = [{ integer: 4 }, { integer: 3 }, { integer: 2 }]
const input3 = [{ integer: 1 }, { integer: 3 }, { integer: 4 }]
const actual = utils.findLargestInteger(input)
const actual2 = utils.findLargestInteger(input2)
const actual3 = utils.findLargestInteger(input3)
expect(actual).toBe(3)
expect(actual2).toBe(4)
expect(actual3).toBe(4)
})
})

describe('[Exercise 4] Counter', () => {
Expand Down