Skip to content

Instantly share code, notes, and snippets.

View blentz100's full-sized avatar
🎯
Focusing

Brendan Lentz blentz100

🎯
Focusing
View GitHub Profile
@blentz100
blentz100 / rotateMatrix.js
Created February 19, 2024 22:28
Cracking the Coding Interview Matrix Problem
const inputMatrix = [
[1, 1, 4, 1],
[4, 3, 3, 6],
[5, 3, 4, 6],
[9, 3, 5, 5],
];
const outputMatrix = [
[9, 5, 4, 1],
[3, 3, 3, 1],
[5, 4, 3, 4],
@blentz100
blentz100 / Best Time to Buy
Created July 1, 2022 00:03
Best Time to Buy - Leetcode Problem
//https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
// in progress, almost there!
/**
* @param {number[]} prices
* @return {number}
*/
var maxProfit = function(prices) {
let currentBest = 0;
//let pricesCopy = [...prices]
@blentz100
blentz100 / reduce.js
Last active June 16, 2022 23:58
Use the reduce Method to Analyze Data
// The global variable
const watchList = [
{
"Title": "Inception",
"Year": "2010",
"Rated": "PG-13",
"Released": "16 Jul 2010",
"Runtime": "148 min",
"Genre": "Action, Adventure, Crime",
"Director": "Christopher Nolan",
@blentz100
blentz100 / Loops Practice
Created June 10, 2022 18:22
Loops Practice
// this is a basic for loop, uses modulus operator, prints 0 to 100 for even
// numbers
for (let i = 0; i < 100; i++){
if (i % 2 == 1){
console.log(i);
}
else {
}
}
@blentz100
blentz100 / gist:482a5b010eac1d08ccd896d8f9330030
Created June 9, 2022 23:50
Largest Prime Factor Freecodecamp Challenge
// https://www.freecodecamp.org/learn/coding-interview-prep/project-euler/problem-3-largest-prime-factor
//a prime is only divisible by 1 and itself
// we need a loop, with an if divisible
//in a loop test for all factors of given number
//then we need to test those for primeness
function largestPrimeFactor(number) {
@blentz100
blentz100 / Problem 2: Even Fibonacci Numbers
Created May 12, 2022 23:58
Problem 2: Even Fibonacci Numbers
//https://www.freecodecamp.org/learn/coding-interview-prep/project-euler/problem-2-even-fibonacci-numbers
function fiboEvenSum(n) {
// write a fibo sequence generator
let fiboArr = [1,2]
for(let i=0; i < n; i++){
fiboArr.push(fiboArr[i] + fiboArr[i+1])
}
console.log(fiboArr)
@blentz100
blentz100 / Problem 9: Special Pythagorean triplet
Created May 6, 2022 00:06
Problem 9: Special Pythagorean triplet
// Problem 9: Special Pythagorean triplet
// https://www.freecodecamp.org/learn/coding-interview-prep/project-euler/problem-9-special-pythagorean-triplet
function specialPythagoreanTriplet(n) {
let sumOfabc = n;
/*
a b c
1 2 3
2 3 4
@blentz100
blentz100 / functions.js
Last active April 29, 2022 15:21
Intro to Javascript Week 3 and Week 4 code examples of functions
//regular function example with a return
function addition(number){
return number + 100;
}
console.log(addition(66))
//arrow function example
const additionV2 = number => number + 100;
console.log(additionV2(66))
@blentz100
blentz100 / classes.js
Last active April 29, 2022 15:59
Intro to Javascript Week 5 - Object Oriented Programming
// League is a Class
// WNBA, NBA, NFL, NHL, MLB, would be objects of this class
// Sport Type, Name of the League, Country, Gender
//class definition
class League {
constructor(leagueName){
this.leagueName = leagueName;
this.teams = [];
@blentz100
blentz100 / gist:3734b2141479311f74f83ecb83770600
Last active April 29, 2022 15:20
Ajax example for crudcrud.com
class House {
constructor(name) {
this.name = name;
this.rooms = [];
}
addRoom(name, area) {
this.rooms.push(new Room(name, area));
}
}