Skip to content

Instantly share code, notes, and snippets.

View takuyadev's full-sized avatar
🔥
Coding grind!

Takuya Toyokawa takuyadev

🔥
Coding grind!
View GitHub Profile
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
@takuyadev
takuyadev / library.js
Last active March 16, 2023 20:02 — forked from kvirani/library.js
Music Library Exercise
/////////////////////////////
// HELPER FUNCTIONS:
/////////////////////////////
// Loop through properties
// Pass object to callback function
const useProperties = (obj, callbackFn) => {
let result = [];
for (const key in obj) {
@takuyadev
takuyadev / dayCalculator.js
Last active March 16, 2023 20:04 — forked from kvirani/dayCalculator.js
W1D2 - Stretch debug challenge
// 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]);
@takuyadev
takuyadev / printInFrame.js
Last active March 16, 2023 20:04 — forked from kvirani/printInFrame.js
W1D2 - Debugging stretch activity
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)}*`);
}
@takuyadev
takuyadev / palindrome.js
Last active March 16, 2023 20:05 — forked from rafd/palindrome.js
W1D2 - Debugging Incorrect Code
// 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
@takuyadev
takuyadev / average.js
Last active March 16, 2023 20:05 — forked from kvirani/average.js
Debugging Errors
function average(list) {
var sum = 0;
for (var num of list) {
sum += num;
}
return sum / list.length;
}
@takuyadev
takuyadev / joinList.js
Last active March 16, 2023 20:05 — forked from kvirani/joinList.js
Lighthouse Labs Week 1 - join concepts
/*
* 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.
*/
@takuyadev
takuyadev / lunch.js
Last active March 16, 2023 20:05 — forked from NimaBoscarino/lunch.js
W1D1 - What to do for Lunch?
/*
* 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.
*