Q1. Make a String out of a array
// question
const fruits = ["apple", "banna", "orange"];
// answer
const result = fruits.join(",");
Q2. Make an Array out of a string
// question
const fruits = "appale, kiwi, banana, cherry";
// answer
const result = fruits.split();
Q3. Make an Array reverse
// question
const array = [1, 2, 3, 4, 5];
// answer
const result = array.resverse();
Q4. Make new array without the first to elements
// question
const array = [1, 2, 3, 4, 5];
// answer
const result = array.slice(2, 5);
Q5. Class Question
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',19,true,88)
]
Q5-1. find a student with the score 90
// answer
const result = students.filiter((item, index, self) => item.score == 90);
Q5-2. make an array containing only the students` scores
// question
// result should be: [45, 80, 90, 66, 88]
// answer
const result = students.map((item, index, self) => item.score);
Q5-3. Check if there is a student with the score lower than 50
// answer
const result = students.every((item, index, self) => item.score >= 50);
// or...
const reulst2 = students.some((item, index, self) => item.score < 50);
Q5-4 Compute students` average scroe
// answer
const result =
students.reduce(
(accumulator, currentValue, currentIndex, self) =>
accumulator + currentValue.score,
0
) / students.length;
Q5-5 Make a String containing all the scores
// result should be: '45, 80, 90, 66, 88'
const result = students.map((item, index, self) => item.score).join();
Q5-6 Sort in ascending order
// result should be :'45,66,80,88,90'
const result = students
.map((item, index, self) => item.score)
.sort((a, b) => a - b);
.join()
๋๊ธ๋จ๊ธฐ๊ธฐ