-
Notifications
You must be signed in to change notification settings - Fork 104
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
Carina Taveras #102
Open
tCarina
wants to merge
3
commits into
joinpursuit:master
Choose a base branch
from
tCarina:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Carina Taveras #102
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,9 @@ | |
* @returns {number} The number of apples Eve has. | ||
*/ | ||
|
||
const eveAppleCount = () => {}; | ||
const eveAppleCount = (appleCountByName) => { | ||
return appleCountByName["Eve"]; | ||
}; | ||
|
||
/** | ||
* Takes in an object with peoples names as the keys and | ||
|
@@ -22,7 +24,9 @@ const eveAppleCount = () => {}; | |
* bracket notation? Try them both. | ||
*/ | ||
|
||
const appleCount = () => {}; | ||
const appleCount = (appleCountByName, name) => { | ||
return appleCountByName[name]; | ||
}; | ||
|
||
/** | ||
* Takes in an object with peoples names as the keys and | ||
|
@@ -36,7 +40,10 @@ const appleCount = () => {}; | |
* @returns {Object} The updated object. | ||
*/ | ||
|
||
const eveAppleSet = () => {}; | ||
const eveAppleSet = (appleCountByName, appleCount) => { | ||
appleCountByName.Eve = appleCount; | ||
return appleCountByName; | ||
}; | ||
|
||
/** | ||
* Takes in an object with peoples names as the keys and | ||
|
@@ -50,7 +57,10 @@ const eveAppleSet = () => {}; | |
* | ||
*/ | ||
|
||
const appleSet = () => {}; | ||
const appleSet = (appleCountByName, name, newAppleCount) => { | ||
appleCountByName[name] = newAppleCount; | ||
return appleCountByName; | ||
}; | ||
|
||
/** | ||
* Takes in an object with peoples names as the keys and | ||
|
@@ -61,7 +71,9 @@ const appleSet = () => {}; | |
* | ||
*/ | ||
|
||
const adamAndEveApples = () => {}; | ||
const adamAndEveApples = (appleCountByName) => { | ||
return appleCountByName["Eve"] + appleCountByName["Adam"]; | ||
}; | ||
|
||
/** | ||
* Takes in an object with peoples names as the keys and | ||
|
@@ -72,7 +84,13 @@ const adamAndEveApples = () => {}; | |
* | ||
*/ | ||
|
||
const appleSum = () => {}; | ||
const appleSum = (appleCountByName) => { | ||
let sum = 0; | ||
for (const key in appleCountByName) { | ||
sum += appleCountByName[key]; | ||
} | ||
return sum; | ||
}; | ||
|
||
/** | ||
* Takes in an object with peoples names as the keys and | ||
|
@@ -83,7 +101,12 @@ const appleSum = () => {}; | |
* | ||
*/ | ||
|
||
const appleSetToZero = () => {}; | ||
const appleSetToZero = (appleCountByName) => { | ||
for (const key in appleCountByName) { | ||
appleCountByName[key] = 0; | ||
} | ||
return appleCountByName; | ||
}; | ||
|
||
/** | ||
* Takes in an object of countries and their capitals. | ||
|
@@ -93,7 +116,9 @@ const appleSetToZero = () => {}; | |
* @returns {string} Capital of Russia | ||
*/ | ||
|
||
const russiaCapital = () => {}; | ||
const russiaCapital = (capitalByCountry) => { | ||
return capitalByCountry["Russia"]; | ||
}; | ||
|
||
/** | ||
* Takes in an object of countries and their capitals. | ||
|
@@ -105,7 +130,9 @@ const russiaCapital = () => {}; | |
* @returns {string} Capital of country | ||
*/ | ||
|
||
const getCapital = () => {}; | ||
const getCapital = (capitalByCountry, country) => { | ||
return capitalByCountry[country]; | ||
}; | ||
|
||
/** | ||
* Takes in an object of countries and their capitals | ||
|
@@ -116,7 +143,10 @@ const getCapital = () => {}; | |
* @returns {Object} countriesAndCapitals now with Jamaica | ||
*/ | ||
|
||
const addsJamaica = () => {}; | ||
const addsJamaica = (capitalByCountry) => { | ||
capitalByCountry.Jamaica = "Kingston"; | ||
return capitalByCountry; | ||
}; | ||
|
||
/** | ||
* Takes in an object of countries and their capitals | ||
|
@@ -130,7 +160,10 @@ const addsJamaica = () => {}; | |
* @returns {Object} countriesAndCapitals | ||
*/ | ||
|
||
const addsCountry = () => {}; | ||
const addsCountry = (capitalByCountry, country, capital) => { | ||
capitalByCountry[country] = capital; | ||
return capitalByCountry; | ||
}; | ||
|
||
/** | ||
* Takes an array of arrays. First element of inner array is authorName, second element | ||
|
@@ -141,7 +174,13 @@ const addsCountry = () => {}; | |
* @returns {Object} {"Mark Twain": 8.9, "Nathaniel Hawthorne": 5.1} | ||
*/ | ||
|
||
const authorScores = () => {}; | ||
const authorScores = (authors) => { | ||
let newObj = {} | ||
for(let el of authors){ | ||
newObj[el[0]] = el[1] | ||
} | ||
return newObj | ||
} | ||
|
||
/** | ||
* You are given an array of objects. | ||
|
@@ -151,15 +190,33 @@ const authorScores = () => {}; | |
* @returns {string} The full name of person with best score. | ||
*/ | ||
|
||
const bestScore = () => {}; | ||
const bestScore = (submissions) => { | ||
let highScore = {score: -Infinity} | ||
for(let key of submissions){ | ||
if(key.score > highScore.score){ | ||
highScore = key | ||
} | ||
} | ||
return `${highScore.firstName} ${highScore.lastName}` | ||
}; | ||
|
||
/** | ||
* Returns an object where the keys are numbers 1 through 20, | ||
* and their respective values is key cubed (num * num * num). | ||
* @returns {Object} {1: 1, 2: 8, 3: 27...} | ||
*/ | ||
|
||
const cubeObj = () => {}; | ||
const cubeObj = () => { | ||
let num = 1 | ||
let newObj = {} | ||
let i = 1 | ||
while(i <= 20){ | ||
newObj[i] = num * num * num | ||
num++ | ||
i++ | ||
} | ||
return newObj | ||
}; | ||
|
||
/** | ||
* Takes in a string and returns an object with | ||
|
@@ -168,7 +225,20 @@ const cubeObj = () => {}; | |
* @returns {Object} Counts of e and a. {a: 2, e: 1} | ||
*/ | ||
|
||
const countAandE = () => {}; | ||
const countAandE = (string) => { | ||
let str = string.toLowerCase() | ||
let count = { | ||
"a" : 0, | ||
"e" : 0 | ||
}; | ||
for (let i = 0; i < str.length; i++) { | ||
const el = i | ||
if (str[el] === "a" || str[el] === "e") { | ||
count[str[el]] += 1 | ||
} | ||
} | ||
return count; | ||
}; | ||
|
||
/** | ||
* Takes in a string and returns an object with | ||
|
@@ -177,7 +247,18 @@ const countAandE = () => {}; | |
* @returns {Object} Counts of all characters: {a: 2, g: 1, o: 2, d:1, " ": 2, s: 1, n:1, k:1, e: 1} | ||
*/ | ||
|
||
const countOccurance = () => {}; | ||
const countOccurance = (str) => { | ||
let count = {}; | ||
for (let i = 0; i < str.length; i++) { | ||
const el = str[i].toLocaleLowerCase(); | ||
if (count[el] !== undefined) { | ||
count[el] += 1; | ||
} else { | ||
count[el] = 1; | ||
} | ||
} | ||
return count; | ||
}; | ||
|
||
/** | ||
* Takes in a string and returns an object with | ||
|
@@ -187,15 +268,50 @@ const countOccurance = () => {}; | |
* @returns {Object} Counts all characters except spaces {a: 2, g: 1, o: 2, d:1, s: 1, n:a, k:1, e: 1} | ||
*/ | ||
|
||
const countOccuranceNoSpaces = () => {}; | ||
const countOccuranceNoSpaces = (str) => { | ||
let newStr = str.split(" ").join("").toLowerCase() | ||
let count = { } | ||
for(let i = 0; i < newStr.length; i++){ | ||
const el = newStr[i] | ||
if(count[el] !== undefined){ | ||
count[el] += 1 | ||
} else { | ||
count[el] = 1 | ||
} | ||
} | ||
return count | ||
}; | ||
|
||
/** | ||
* Takes in an array and returns the most common element. | ||
* @param {Array} array - array of elements | ||
* @returns {(number|string)} Most common element | ||
*/ | ||
|
||
const mostCommonElement = () => {}; | ||
const mostCommonElement = (array) => { | ||
let obj = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think about splitting this part of your code into a helper function so that each function only does one thing. |
||
for (let i = 0; i < array.length; i++) { | ||
let element = array[i]; | ||
if (obj[element]) { | ||
obj[element] += 1; | ||
} else { | ||
obj[element] = 1; | ||
} | ||
} | ||
let mostCommon = -Infinity; | ||
let commonElement; | ||
for (let key in obj) { | ||
if (obj[key] > mostCommon) { | ||
mostCommon = obj[key]; | ||
commonElement = key; | ||
} | ||
} | ||
if (parseInt(commonElement)) { | ||
return parseInt(commonElement); | ||
} else { | ||
return commonElement; | ||
} | ||
}; | ||
|
||
/** | ||
* Takes in an object and an array. | ||
|
@@ -215,8 +331,19 @@ const mostCommonElement = () => {}; | |
* @returns {string[]} Elements or their pair values. | ||
*/ | ||
|
||
const updateList = () => {}; | ||
|
||
const updateList = (pairs, arr) => { | ||
let newArr = []; | ||
for (let i = 0; i < arr.length; i++) { | ||
let artists = arr[i]; | ||
|
||
if (pairs[artists]) { | ||
newArr.push(pairs[artists]); | ||
} else { | ||
newArr.push(artists); | ||
} | ||
} | ||
return newArr; | ||
}; | ||
/** | ||
* Takes in an object and a key. | ||
* It should delete the key value pair from the object and | ||
|
@@ -226,16 +353,24 @@ const updateList = () => {}; | |
* @returns {Object} The Object without the key. | ||
*/ | ||
|
||
const deleteKey = () => {}; | ||
|
||
const deleteKey = (obj, key) => { | ||
delete obj[key]; | ||
return obj; | ||
}; | ||
|
||
/** | ||
* Takes in an object and returns the number of | ||
* properties it has. | ||
* @param {Object} obj | ||
* @returns {number} Number of properties. | ||
*/ | ||
const propertyCount = () => {}; | ||
/** | ||
* Takes in an object and returns the number of | ||
* properties it has. | ||
* @param {Object} obj | ||
* @returns {number} Number of properties. | ||
*/ | ||
const propertyCount = (obj) => { | ||
let props = 0; | ||
for (key in obj) { | ||
++props; | ||
} | ||
return props; | ||
}; | ||
|
||
module.exports = { | ||
eveAppleCount, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job!