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 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 } |
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 giftCardsInCents = [2000, 3000, 4000, 5500, 35000]; | |
| const giftCardsInDollars = giftCardsInCents.map(cents => cents / 100); | |
| console.log(giftCardsInDollars); // [20, 30, 40, 55, 350] |
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 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; | |
| }); |
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 giftCards = [5, 10, 20, 100, 20]; | |
| const total = giftCards.reduce((accumulator, currentValue) => { | |
| return accumulator + currentValue; | |
| }, 0); | |
| console.log(total); // 155 |
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 shoppingCart = [ | |
| { | |
| item: 'Laptop', | |
| quantity: 1, | |
| price: 1899.99 | |
| }, | |
| { | |
| item: 'Keyboard', | |
| quantity: 1, | |
| price: 49.98 |
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 orders = [ | |
| { | |
| orderId: 5563, | |
| total: 673.33 | |
| }, | |
| { | |
| orderId: 5564, | |
| total: 274.99 | |
| }, | |
| { |
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 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"] |
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 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] |
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 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`); |
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 veggies = ['kale', 'carrots', 'tomato', 'broccoli', 'mushrooms']; | |
| console.log(veggies.indexOf('tomato')); // 2 |