This file contains hidden or 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
def benchmark | |
# Mark current time | |
start_time = Time.now() | |
# Run long callback / yield command | |
yield | |
# Mark end time | |
end_time = Time.now() | |
# Calculate total time using marked times | |
total_time = end_time - start_time |
This file contains hidden or 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
///////////////////////////// | |
// HELPER FUNCTIONS: | |
///////////////////////////// | |
// Loop through properties | |
// Pass object to callback function | |
const useProperties = (obj, callbackFn) => { | |
let result = []; | |
for (const key in obj) { |
This file contains hidden or 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
// Calculating a Leap Year | |
// Divide the year you want to check by 4. If it is not evenly divisible (it has a remainder), it's is not a leap year. If it is evenly divisible (it has no remainder) continue to step 2. | |
// Divide the year by 100. If the year is evenly divisible by 4 but is not evenly divisible by 100, it is a leap year. If it is evenly divisible by both 4 and 100, continue to step 3. | |
// Divide the year by 400. If the year is evenly divisible by 100, but is not evenly divisible by 400, it is not a leap year. If it is evenly divisible by both 100 and 400, it is a leap year. | |
function calculateDayInYear(date) { | |
// Converts the string date into readable dates, converted into Number data type | |
const splitDate = date.split("/"); | |
const year = Number(splitDate[0]); |
This file contains hidden or 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
const printInFrame = function(list) { | |
list = list.split(' '); | |
const longest = longestStr(list).length; | |
// Problem 1: Since there's 2 space and 2 * you have to account for, you have to add 4 to the longest to accommodate for the length | |
const border = repeat('*', longest + 4); | |
console.log(border); | |
for (const word of list) { | |
console.log(`* ${word}${repeat(' ', longest - word.length + 1)}*`); | |
} |
This file contains hidden or 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
// FUNCTION IMPLEMENTATION (MULTIPLE BUGS) | |
const isPalindrome = function (str) { | |
//Bonus: When checking, it uses strict operator, so lowercase new string or loose check | |
const noSpaces = str.split(" ").join("").toLowerCase(); | |
const midIndex = Math.floor(noSpaces.length / 2); | |
const lastIndex = noSpaces.length - 1; | |
for (let i = 0; i < midIndex; i++) { | |
// Problem 1: used str instead of noSpaces, meaning letter retrieved was cooming from str instead of trimmed noSpaces |
This file contains hidden or 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
function average(list) { | |
var sum = 0; | |
for (var num of list) { | |
sum += num; | |
} | |
return sum / list.length; | |
} |
This file contains hidden or 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
/* | |
* Write a function that joins the contents of conceptList together | |
* into one String, concepts, with each list item separated from | |
* the previous by a comma. | |
* | |
* To implement this we'll create a joinList function which will take | |
* in any array of strings return a comma-separated string. | |
* | |
* Note: We can NOT use the built-in Array join function. | |
*/ |
This file contains hidden or 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
/* | |
* Modify the contents of the function below, such that: | |
* | |
* If we're not hungry, we want to tell ourselves to get back to work. | |
* Otherwise, we want to pick something up and eat it in the lab when | |
* we've got less than 20 minutes or to try a place nearby if we've | |
* got between 20 and 30 minutes. If we have any more time than that, | |
* we want to remind ourselves that we're in a bootcamp and that we | |
* should reconsider how much time we actually have to spare. | |
* |