Skip to content

Instantly share code, notes, and snippets.

View sandrabosk's full-sized avatar
👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall

Aleksandra Bošković sandrabosk

👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall
  • Ironhack
View GitHub Profile

🙌 Week 12 - Day 1

Class duration: 180 min

Setup (reflects to all the lessons):

  • No additional setup required

// ************************************************************************************
// https://www.codewars.com/kata/5848565e273af816fb000449/javascript
// Description:
// Encrypt this!
// You want to create secret messages which can be deciphered by the Decipher this! kata.
// Here are the conditions:
// Your message is a string containing space separated words.
// ************************************************************************************
// https://www.codewars.com/kata/the-hashtag-generator
// The marketing team is spending way too much time typing in hashtags.
// Let's help them with our own Hashtag Generator!
// Here's the deal:
// It must start with a hashtag (#).
// All words must have their first letter capitalized.
// If the final result is longer than 140 chars it must return false.

logo_ironhack_blue 7

Rooms App with Reviews - final practice for project #2

Introduction

In previous lessons, we covered all the basics one full stack app can have. Now is the time for you to implement all these features one more time.

Instructions

  1. Calculate the total population in the given array (data):
const data = [
  {
    country: 'USA',
    pop: 340,
  },
  {
 country: 'France',

.sort()

  • mutates the original array - to prevent it, make a copy (const sorted = origArr.slice().sort() or const sorted1 = [...origArr]) of the array and then sort the copy
  • makes a specific order of elements
  • returns array
  • sorts by a string value (even if it's an array of numbers)

There's plenty of ways to sort arrays in JavaScript (and using .sort() is probably one of the slowest ones, but it is important to understand it and how it works).

const arrOfStrings = ['cat', 'wolf', 'yo', 'animal'];
  • Exercise 1: Using the array (arrOfStrings), sort an array from shortest string to the longest.

  • Exercise 2: Using the same arr (arrOfStrings), sort its elements alphabetically.

  • Exercise 3: Sort the objects in the array by age, in descending order.

  1. Given an array of numbers, filter out the numbers that are not even, and are less than 100.
const numbers = [1, 60, 112, 123, 100, 99, 73, ];

// ... your code here
  1. From the given array of people, get the people who are allowed to consume alcoholic beverages (based on the US law). Bonus: Get just their names, we don't need their age.

Callbacks

CALLBACKS are a way to make sure certain code doesn’t execute until another code has already finished execution.

Let's check this example:

  • function 1:
function study(what){
 console.log(`I am studying ${what}.`)