Skip to content

Instantly share code, notes, and snippets.

View jtreeves's full-sized avatar

Jackson Reeves jtreeves

View GitHub Profile
for (let i = 0; i < mainArray.length; i++) {
for (let j = 0; j < otherArray.length; j++) {
if (mainArray[i].commonKey === otherArray[j].commonKey) {
mainArray[i].newKey = otherArray[j]
}
}
}
router.get('/rated', (req, res) => {
db.rating
.findAll({
where: { userId: res.locals.currentUser.id }
})
.then(responses => {
let books = []
for (let i = 0; i < responses.length; i++) {
books[i] = {
id: responses[i].bookId,
function maxOfThree(num1, num2, num3) {
if (num1 > num2 && num1 > num3) {
return num1;
} else if (num2 > num1 && num2 > num3) {
return num2;
} else if (num3 > num1 && num3 > num2) {
return num3;
} else if (num1 === num2 === num3) {
return "These numbers are identical.";
} else if (num1 === num2 || num2 === num3 || num1 === num3) {
@jtreeves
jtreeves / tripler.js
Created October 25, 2020 02:22
Tripler
function tripler(array) {
// Confirm in the function
console.log('Inside the tripler() function:');
// Take in an array, and return a new array
const result = [];
// Iterate through array passed in
for (let i = 0; i < array.length; i++) {
let num = array[i];
// Multiply each element by 3
let multiple = num * 3;
@jtreeves
jtreeves / mqr.py
Created October 24, 2020 23:07
MQR
def mqr(raw_data):
sorted_data = sorted(raw_data)
count = len(sorted_data)
fifth = math.ceil(count / 5.0)
contenders = []
num = 0
while num < count - fifth:
contenders.append(sorted_data[num + fifth - 1] - sorted_data[num])
num += 1
return contenders