From 8b396eec6556ee1674f80c6b270ee4d21c6e1b77 Mon Sep 17 00:00:00 2001
From: Alejandro <alepeddia@gmail.com>
Date: Fri, 10 Sep 2021 12:23:03 +0200
Subject: [PATCH] Solutions & videos

---
 ReadMe.md    |  2 ++
 index.html   | 12 ++++++++
 worksheet.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+)
 create mode 100644 index.html

diff --git a/ReadMe.md b/ReadMe.md
index 9e39619..3fca8f1 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -2,6 +2,8 @@
 
 Want to learn how to use JavaScript array functions like map, reduce, filter, etc? Use this worksheet and the corresponding videos to figure out how!
 
+Videos: https://www.youtube.com/playlist?list=PLDlWc9AfQBfZGZXFb_1tcRKwtCavR7AfT
+
 ## Sample Data
 
 Here's a sample piece of Star Wars data from the [Star Wars API](https://swapi.dev/).
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..241d492
--- /dev/null
+++ b/index.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body style="background-color: black;">
+    <script src="worksheet.js"></script>
+</body>
+</html>
\ No newline at end of file
diff --git a/worksheet.js b/worksheet.js
index 99cdfd5..767d1e0 100644
--- a/worksheet.js
+++ b/worksheet.js
@@ -31,36 +31,115 @@ const characters = [
 
 //***MAP***
 //1. Get array of all names
+const names = characters.map(character => character.name);
+console.log(names);
+
 //2. Get array of all heights
+const heights = characters.map(character => character.height);
+console.log(heights);
+
 //3. Get array of objects with just name and height properties
+const mapTres = characters.map(character => ({
+  name: character.name,
+  height: character.height,
+}));
+console.log(mapTres);
+
 //4. Get array of all first names
+const firstName = characters.map(
+  character =>
+    //   character.name.slice(0, character.name.indexOf(' ')));
+    character.name.split(' ')[0]
+);
+console.log(firstName);
 
 //***REDUCE***
 //1. Get total mass of all characters
+const totalMass = characters.reduce((acc, cur) => acc + +cur.mass, 0);
+console.log(totalMass);
+
 //2. Get total height of all characters
+const totalHeight = characters.reduce((acc, cur) => acc + +cur.height, 0);
+console.log(totalHeight);
+
 //3. Get total number of characters by eye color
+const totalCha = characters.reduce((acc, cur) => {
+  const color = cur.eye_color;
+  if (acc[color]) acc[color]++;
+  else acc[color] = 1;
+  return acc;
+}, {});
+
+console.log(totalCha);
+
 //4. Get total number of characters in all the character names
+const totalLet = characters.reduce((acc, cur) => acc + cur.name.length, 0);
+console.log(totalLet);
 
 //***FILTER***
 //1. Get characters with mass greater than 100
+const massGreater = characters.filter(character => character.mass > 100);
+console.log(massGreater);
+
 //2. Get characters with height less than 200
+const massLess = characters.filter(character => character.mass < 200);
+console.log(massLess);
+
 //3. Get all male characters
+const males = characters.filter(character => character.gender === 'male');
+console.log(males);
+
 //4. Get all female characters
+const females = characters.filter(character => character.gender === 'female');
+console.log(females);
 
 //***SORT***
 //1. Sort by mass
+const byMass = characters.sort((a, b) => b.mass - a.mass);
+console.log(byMass);
+
 //2. Sort by height
+const byHeight = characters.sort((a, b) => b.height - a.height);
+console.log(byHeight);
+
 //3. Sort by name
+const byName = characters.sort((a, b) => (a.name < b.name ? -1 : 1));
+console.log(byName);
+
 //4. Sort by gender
+const byGender = characters.sort((a, b) => (a.gender < b.gender ? -1 : 1));
+console.log(byGender);
 
 //***EVERY***
 //1. Does every character have blue eyes?
+const checkEyes = characters.every(character => character.eye_color === 'blue');
+console.log(checkEyes);
+
 //2. Does every character have mass more than 40?
+const checkMass = characters.every(character => character.mass > 40);
+console.log(checkMass);
+
 //3. Is every character shorter than 200?
+const checkHeight = characters.every(character => character.height < 200);
+console.log(checkHeight);
+
 //4. Is every character male?
+const checkGender = characters.every(character => character.gender === 'male');
+console.log(checkGender);
 
 //***SOME***
 //1. Is there at least one male character?
+const anyMale = characters.some(character => character.gender === 'male');
+console.log(anyMale);
+
 //2. Is there at least one character with blue eyes?
+const anyEyes = characters.some(character => character.eye_color === 'blue');
+console.log(anyEyes);
+
 //3. Is there at least one character taller than 210?
+const anyHeight = characters.some(character => character.height > 210);
+console.log(anyHeight);
+
 //4. Is there at least one character that has mass less than 50?
+const anyMass = characters.some(character => character.mass < 50);
+console.log(anyMass);
