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
66 changes: 54 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
* trimProperties({ name: ' jane ' }) // returns a new object { name: 'jane' }
*/
function trimProperties(obj) {
// ✨ implement
const trimmedObj = {}
for(let prop in obj){
if(typeof obj[prop] === 'string'){
trimmedObj[prop] = obj[prop].trim()
}else{
trimmedObj[prop] = obj[prop]
}
}
return trimmedObj
}

/**
Expand All @@ -19,7 +27,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 @@ -31,7 +42,11 @@ 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 All @@ -40,7 +55,7 @@ class Counter {
* @param {number} initialNumber - the initial state of the count
*/
constructor(initialNumber) {
// ✨ initialize whatever properties are needed
this.count = initialNumber
}

/**
Expand All @@ -56,7 +71,7 @@ class Counter {
* counter.countDown() // returns 0
*/
countDown() {
// ✨ implement
return this.count > 0 ? this.count-- : 0
}
}

Expand All @@ -65,7 +80,8 @@ class Seasons {
* [Exercise 5A] Seasons creates a seasons object
*/
constructor() {
// ✨ initialize whatever properties are needed
this.seasons = ['winter', 'notspring', 'summer', 'fall']
this.currentSeason = 0
}

/**
Expand All @@ -81,7 +97,13 @@ class Seasons {
* seasons.next() // returns "summer"
*/
next() {
// ✨ implement
let theCurrentSeason = this.seasons[this.currentSeason]
if(this.currentSeason === 3){
this.currentSeason = 0
}else{
++this.currentSeason
return theCurrentSeason
}
}
}

Expand All @@ -95,7 +117,9 @@ class Car {
constructor(name, tankSize, mpg) {
this.odometer = 0 // car initilizes with zero miles
this.tank = tankSize // car initiazes full of gas
// ✨ initialize whatever other properties are needed
this.name = name
this.mpg = mpg
this.tankMax = tankSize
}

/**
Expand All @@ -112,7 +136,13 @@ class Car {
* focus.drive(200) // returns 600 (ran out of gas after 100 miles)
*/
drive(distance) {
// ✨ implement
let maxRange = this.tank * this.mpg
if(distance <= maxRange){this.odometer = this.odometer + distance; this.tank = this.tank - distance / this.mpg}
else{
this.tank = 0
this.odometer = this.odometer + maxRange
}
return this.odometer
}

/**
Expand All @@ -127,7 +157,13 @@ class Car {
* focus.refuel(99) // returns 600 (tank only holds 20)
*/
refuel(gallons) {
// ✨ implement
if(this.tank + gallons > this.tankMax){
this.tank = this.tankMax
return Car
}else{
this.tank += gallons
}
return Car
}
}

Expand All @@ -144,8 +180,14 @@ class Car {
* // result is false
* })
*/
function isEvenNumberAsync(number) {
// ✨ implement
async function isEvenNumberAsync(number) {
if(!number || typeof number !== 'number'){
return false
}if(number % 2 ===0){
return true
}else{
return false
}
}

module.exports = {
Expand Down
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.