//Q1. make a string out of an array
{
    const fruits = ['apple', 'banana', 'orange'];
    //console.log(fruits.toString());
    console.log(fruits.join(' and '));
}

//Q2. make an array out of a string
{
    const fruits = '๐Ÿ•,๐Ÿ”,๐ŸŸ,๐ŸŒญ';
    const result = fruits.split(',', 2); // ',' ๊ธฐ์ค€์œผ๋กœ 2๊ฐœ๋งŒ ์ถœ๋ ฅํ•˜๋ผ. ์ƒˆ๋กœ์šด ๋ฐฐ์—ด return
    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);
    console.log(array); // ๊ธฐ์กด ๋ฐฐ์—ด๋„ ๋’ค์ง‘ํž˜
}

//Q4. make new array without the first two elements
{
    const array = [1, 2, 3, 4, 5];
    // const newArr = array.splice(0, 2); // ๊ธฐ์กด ๋ฐฐ์—ด์ด ์ž˜๋ฆฐ๋‹ค. 0 ๋ถ€ํ„ฐ 2๊ฐœ ์ž˜๋ผ์ค˜
    // console.log(array); // [3, 4, 5]
		// console.log(newArr); // [1, 2]
    const newArr = array.slice(2, 5); // ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ return. 2๋ฒˆ index ๋ถ€ํ„ฐ 5 - 1๋ฒˆ index๊นŒ์ง€
    console.log(newArr); // [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
{
    // for(const sub of students)
    // {
    //     if(sub.score === 90)
    //        console.log(sub);
    // }

    // const result = students.find(function (student, index){
    //     //console.log(student, index);
    //     return student.score === 90;
    // });

    const result = students.find((student) => student.score === 90);
    console.log(result);
}

console.clear();
//Q6. make an array of enrolled students
{
    const result = students.filter((student) => student.enrolled === true);
    console.log(result);
}

console.clear();

//Q7. make an array containing only the student's scores
//result should be: [45, 80, 90, 66, 88]
//๋ฐ›์€ ๊ฐ’์„ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•ด์„œ ๋„˜๊ฒจ ์ค„์ง€ ์ •ํ•ด์ค€๋‹ค.
{
    const result = students.map((student) => student.score * 2);
    console.log(result); // [90, 160, 180, 132, 176] return
}
console.clear();
//Q8. check if there is a student with the score lower than 50
{
    const result = students.some((student) => student.score < 50); // some ์€ boolean
    console.log(result);
}

console.clear();
//Q9. compute students' average score
{
    const result = students.reduce((prev, curr) => prev + curr.score, 0);

    console.log(result);
}

//Q10. make a string containing all the scores
// result should be: '45, 66, 80, 90
{
    const resultl = students.map((student) => student.score)
    .filter((score) => score >= 50) // 50์  ์ด์ƒ์ธ ์• ๋“ค๋งŒ filtering
    .join();
    console.log(resultl);
}
console.clear();
//sort
{
    const result = students
    .map((student) => student.score)
    .sort((a, b) => a - b)
    .join();
    console.log(result);
}

splice โ†’ ์ž˜๋ฆฐ elem return, ๊ธฐ์กด ๋ฐฐ์—ด๋„ ์ž˜๋ฆผ

slice โ†’ start ~ end ์ด์ „๊นŒ์ง€ ํ•ด์„œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด return, ๊ธฐ์กด ๋ฐฐ์—ด์€ ๊ทธ๋Œ€๋กœ

๋ฌธ์ž์—ด split โ†’ arg ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆ”, ์ƒˆ๋กœ์šด ๋ฐฐ์—ด return, ๊ธฐ์กด ๋ฐฐ์—ด์€ ๊ทธ๋Œ€๋กœ