ํฐ์คํ ๋ฆฌ ๋ทฐ
Javascript
[๋๋ฆผ์ฝ๋ฉ by ์๋ฆฌ] 9. ์ ์ฉํ 10๊ฐ์ง ๋ฐฐ์ด ํจ์๋ค. Array APIs ์ด์ ๋ฆฌ
๋๋ NANNA 2021. 9. 13. 17:10๋ฐ์ํ
// Q1. make a string out of an array
{
const fruits = ['apple', 'banana', 'orange'];
const result = fruits.join();
console.log(result);
// apple,banana,orange
}
// Q2. make an array out of a string
{
const fruits = '๐, ๐ฅ, ๐, ๐';
const result = fruits.split(',');
console.log(result);
// ["๐", "๐ฅ", "๐", "๐"]
}
// Q3. make this array look like this: [5, 4, 3, 2, 1]
{
const array = [1, 2, 3, 4, 5];
const result = array.reverse();
console.log(result);
// [5, 4, 3, 2, 1]
console.log(array);
// [5, 4, 3, 2, 1]
// ์๋ณธ๋ ๋ฐ๋
}
// Q4. make new array without the first two elements
{
const array = [1, 2, 3, 4, 5];
const result = array.slice(2, 5);
console.log(result);
// [3, 4, 5]
console.log(array);
// [1, 2, 3, 4, 5]
}
class Student {
constructor(name, age, enrolled, score) {
this.name = name;
this.age = age;
this.enrolled = enrolled;
this.score = score;
}
}
const students = [
new Student('A', 29, true, 45),
new Student('B', 28, false, 80),
new Student('C', 30, true, 90),
new Student('D', 40, false, 66),
new Student('E', 18, true, 88),
];
// Q5. find a student with the score 90
{
const result = students.find((student) => student.score === 90);
}
// Q6. make an array of enrolled students
{
const result = students.filter((student) => student.enrolled);
}
// Q7. make an array containing only the students' scores
// result should be: [45, 80, 90, 66, 88]
{
const result = students.map((student) => student.score);
}
// Q8. check if there is a student with the score lower than 50
{
const result = students.some((student) => student.score < 50);
const result2 = !students.every((student) => student.score >= 50);
}
// Q9. compute students' average score
{
const result = students.reduce((prev, curr) => prev + curr.score, 0) / students.length;
}
// Q10. make a string containing all the scores
// result should be: '45, 80, 90, 66, 88'
{
const result = students
.map(student => student.score)
.join();
}
// Bonus! do Q10 sorted in ascending order
// result should be: '45, 66, 80, 88, 90'
{
const result = students.map(student => student.score)
.sort()
.join();
}
๋ฐ์ํ
'Javascript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- git
- 42cursus
- CS50
- ๋ฉ์์ด์ฌ์์ฒ๋ผ9๊ธฐ
- ๋๋ฆผ์ฝ๋ฉ
- ์ฝ๋ํฌ์ค
- ๋ถ์คํธ์ฝ์ค
- ์๊ณ ๋ฆฌ์ฆ
- 42์์ธ
- ๋๋ฆผ์ฝ๋ฉby์๋ฆฌ
- C++
- django
- codeforces
- ์ฝ๋ฆฐ์ด์ ์ฑ์ฅ์ผ๊ธฐ
- BOJ
- Python
- ๋ถ์คํธ์ฝ๋ฉ๋ด๋น์ฑ๋ฆฐ์ง
- 42seoul
- ES6
- ์ฝ๋ฉ๋ด๋น์ฑ๋ฆฐ์ง
- ft_server
- ๋ฐฑ์ค
- ์ฝ๋ฆฐ์ด
- ๋ค์ด๋ฒ์ปค๋ฅํธ์ฌ๋จ
- ์๋ฐ์คํฌ๋ฆฝํธ
- ft_printf
- ๋ฉ์์ด์ฌ์์ฒ๋ผ
- printf
- ์ปดํจํฐ๊ณผํ
- github
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
๊ธ ๋ณด๊ดํจ