Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

My solution#1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
zicna wants to merge2 commits intojamesqquick:masterfromzicna:my_solution
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletionsindexx.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -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>
<script src="worksheet.js"></script>
</body>
</html>
108 changes: 76 additions & 32 deletionsworksheet.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,95 @@
const characters = [
{
name:'Luke Skywalker',
height: 172,
mass: 77,
eye_color:'blue',
gender:'male',
},
{
name:'Darth Vader',
height: 202,
mass: 136,
eye_color:'yellow',
gender:'male',
},
{
name:'Leia Organa',
height: 150,
mass: 49,
eye_color:'brown',
gender:'female',
},
{
name:'Anakin Skywalker',
height: 188,
mass: 84,
eye_color:'blue',
gender:'male',
},
{
name:"Luke Skywalker",
height: 172,
mass: 77,
eye_color:"blue",
gender:"male",
},
{
name:"Darth Vader",
height: 202,
mass: 136,
eye_color:"yellow",
gender:"male",
},
{
name:"Leia Organa",
height: 150,
mass: 49,
eye_color:"brown",
gender:"female",
},
{
name:"Anakin Skywalker",
height: 188,
mass: 84,
eye_color:"blue",
gender:"male",
},
];
console.log(characters);

//***MAP***
//1. Get array of all names

let allNames = characters.map((e) => e.name);
// console.log(allNames)
//2. Get array of all heights
let allHeights = characters.map((e) => e.height);
// console.log(allHeights)
//3. Get array of objects with just name and height properties
const obj = characters.map((element) => {
return { name: element.name, height: element.height };
});
// console.log(obj)
//4. Get array of all first names
const firstName = characters.map((e) => {
return e.name.split(" ")[0];
});
// console.log(firstName)

//***REDUCE***
//1. Get total mass of all characters
const allMass = characters.reduce((acc, currentEl) => {
return acc + currentEl.mass;
}, 0);

// console.log(allMass);
//2. Get total height of all characters
const totalHeight = characters.reduce((acc, currentEl) => {
return acc + currentEl.height
},0)
// console.log(totalHeight)
//3. Get total number of characters by eye color
const byEyeColor = characters.reduce((acc, currentEl) => {
if(acc[currentEl.eye_color]) {
acc[currentEl.eye_color] ++
} else {
acc[currentEl.eye_color] = 1
}
return acc
}, {})
// console.log(byEyeColor)
//4. Get total number of characters in all the character names
const totalNameCharacters = characters.reduce((acc, currentEl) => {
return acc + currentEl.name.length
},0)
// console.log(totalNameCharacters)

//***FILTER***
//1. Get characters with mass greater than 100
//2. Get characters with height less than 200
//3. Get all male characters
//4. Get all female characters
//?1. Get characters with mass greater than 100
const charMassGreather = characters.filter(element => element.mass > 100)
// console.log(charMassGreather)
//?2. Get characters with height less than 200
const filterHeight = characters.filter(element => element.height < 200)
// console.log(filterHeight)
//?3. Get all male characters
const allMale = characters.filter(element => element.gender === "male")
// console.log(allMale)
//?4. Get all female characters
const allFemale = characters.filter(element => element.gender === "female")
// console.log(allFemale)

//***SORT***
//1. Sort by mass
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp