Skip to content

Instantly share code, notes, and snippets.

View kluu1's full-sized avatar

Kevin Luu kluu1

  • Atlanta, GA
View GitHub Profile
@kluu1
kluu1 / users.js
Last active March 19, 2020 01:38
const mongoose = require('mongoose');
const { Schema } = mongoose;
const userSchema = new Schema({
id: { type: String, required: true, index: { unique: true } },
firstName: { type: String, required: true },
lastName: { type: String, required: true },
userName: { type: String, required: true },
email: { type: String, required: true },
jobTitle: { type: String, required: false }
@kluu1
kluu1 / map1.js
Last active March 20, 2020 02:38
const giftCardsInCents = [2000, 3000, 4000, 5500, 35000];
const giftCardsInDollars = giftCardsInCents.map(cents => cents / 100);
console.log(giftCardsInDollars); // [20, 30, 40, 55, 350]
@kluu1
kluu1 / map2.js
Last active March 20, 2020 02:44
const employees = [
{ id: 2002, name: 'Jordan Lake' },
{ id: 2008, name: 'Barney Veers' },
{ id: 5738, name: 'Amber Lee' },
{ id: 8835, name: 'James Herring' }
];
const employeeIds = employees.map(employee => {
return employee.id;
});
const giftCards = [5, 10, 20, 100, 20];
const total = giftCards.reduce((accumulator, currentValue) => {
return accumulator + currentValue;
}, 0);
console.log(total); // 155
const shoppingCart = [
{
item: 'Laptop',
quantity: 1,
price: 1899.99
},
{
item: 'Keyboard',
quantity: 1,
price: 49.98
const orders = [
{
orderId: 5563,
total: 673.33
},
{
orderId: 5564,
total: 274.99
},
{
const zoo = ['tiger', 'horse', 'tiger', 'lion', 'snake', 'bear', 'tiger'];
const animals = zoo.filter((animal, index) => animal.indexOf(animal) !== index);
console.log(animals); // ["horse", "tiger", "lion", "snake", "bear", "tiger"]
const day1 = [1399.99, 376.33, 542.43]
const day2 = [809.99, 376.3312, 952.77]
const day3 = [199.99, 976.43, 752.33]
const orders = day1.concat(day2).concat(day3);
console.log(orders); // [1399.99, 376.33, 542.43, 809.99, 376.3312, 952.77, 199.99, 976.43, 752.33]
const shoppingCart = ['desktop', 'keyboard', 'speakers', 'mouse'];
const addToCart = (cart, item) => {
// checks if item does not exist in cart
if (cart.indexOf(item) === -1) {
console.log(`${item} has been added to the shopping cart`);
return cart.push(item);
}
return console.log(`${item} is already in the shopping cart`);
const veggies = ['kale', 'carrots', 'tomato', 'broccoli', 'mushrooms'];
console.log(veggies.indexOf('tomato')); // 2