From f26ecd4bdd8804ff394abb6edbc35d8c123f7993 Mon Sep 17 00:00:00 2001 From: tamara-taylor Date: Wed, 19 Jan 2022 17:57:58 -0500 Subject: [PATCH] tests passing --- index.js | 66 ++++++++++++++++++++++++++++++++++++++--------- package-lock.json | 6 +++-- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 3df06ec1..a0727582 100644 --- a/index.js +++ b/index.js @@ -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 } /** @@ -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 } /** @@ -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 { @@ -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 } /** @@ -56,7 +71,7 @@ class Counter { * counter.countDown() // returns 0 */ countDown() { - // ✨ implement + return this.count > 0 ? this.count-- : 0 } } @@ -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 } /** @@ -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 + } } } @@ -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 } /** @@ -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 } /** @@ -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 } } @@ -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 = { diff --git a/package-lock.json b/package-lock.json index 880aab90..21ecb81a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,6 @@ "requires": true, "packages": { "": { - "name": "node-testing1-project", "version": "1.0.0", "devDependencies": { "@types/jest": "^27.0.3", @@ -1650,6 +1649,7 @@ "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", + "fsevents": "~2.3.2", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", @@ -2109,7 +2109,8 @@ "esprima": "^4.0.1", "estraverse": "^5.2.0", "esutils": "^2.0.2", - "optionator": "^0.8.1" + "optionator": "^0.8.1", + "source-map": "~0.6.1" }, "bin": { "escodegen": "bin/escodegen.js", @@ -3357,6 +3358,7 @@ "@types/node": "*", "anymatch": "^3.0.3", "fb-watchman": "^2.0.0", + "fsevents": "^2.3.2", "graceful-fs": "^4.2.4", "jest-regex-util": "^27.4.0", "jest-serializer": "^27.4.0",