티스토리 뷰
Quiz
// 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);
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);
console.log(result);
// Q6. make an array of enrolled students
const result = students.filter(student => student.enrolled === true);
console.log(result);
// Q7. make an array containing only the students' scores
// result should be: [45, 80, 90, 66, 88]
const result = students.map((student) => student.score);
console.log(result);
// Q8. check if there is a student with the score lower than 50
const result = students.some((student) => student.score < 50);
console.log(result); // true
const result2 = students.every((student) => student.score >= 50);
console.log(result2); // true
// Q9. compute students' average score
const result = students.reduce((prev, curr) => prev + curr.score, 0);
console.log(result / 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)
.filter(score => score >= 50)
.join();
console.log(result); // 50점 이상
// Bonus! do Q10 sorted in ascending order
// result should be: '45, 66, 80, 88, 90'
const result = students
.map((student) => student.score)
.sort((a, b) => a - b)
.join();
console.log(result);
- join
- split
- reverse
- slice
- find
- filter
- map
- some
- every
- reduce
※출처
반응형
'JavaScript & TypeScript' 카테고리의 다른 글
10. Callback (0) | 2020.11.15 |
---|---|
9. JSON (0) | 2020.11.15 |
7. Array, API (0) | 2020.11.14 |
6. what is object (0) | 2020.11.14 |
5. class vs object (0) | 2020.11.14 |
링크
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- HTTP 완벽가이드
- 킹수빈닷컴
- 이펙티브자바 아이템59
- 이펙티브자바
- 이펙티브자바 아이템60
- 김영한 JPA
- 프로그래머스 SQL
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- js api
- dreamcoding
- 모던자바스크립트
- GCP
- 백준
- 이펙티브자바 스터디
- BOJ
- java
- js array
- REST API
- 패스트캠퍼스 컴퓨터공학 완주반
- 백기선 스터디
- HTTP 완벽 가이드
- 집 구하기
- http
- JPA 연관관계 매핑
- 프로그래머스
- JS 딥다이브
- 김영한 http
- js promise
- 드림코딩
- Spring Security
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함