const numbers = [15, 8, 23, 4, 42, 16, 7];
const students = [
    { name: '张三', score: 85 },
    { name: '李四', score: 62 },
    { name: '王五', score: 91 }
];

console.log('1. slice() - 数组切片');
const sliced = numbers.slice(1, 4);
console.log('numbers.slice(1, 4):', sliced);

console.log('\n2. filter() - 筛选元素');
const evenNumbers = numbers.filter(numbers => numbers % 3 == 0);
console.log('偶数:', evenNumbers);

console.log('\n3. find() - 查找元素');
const findScore = students.find(student => student.score > 90);
console.log('分数>90的学生:', findScore);

console.log('\n4. findIndex() - 查找索引');
const index = numbers.findIndex(numbers => numbers > 20);
console.log('第一个>20的数的索引:', index);

console.log('\n5. every() - 所有元素满足条件');

const allPassed = students.every(student => student.score >= 60);
console.log('所有学生都及格:', allPassed);


console.log('\n6. some() - 至少一个满足条件');
const hasHighScore = students.some(student => student.score > 90);
console.log('有高分学生:', hasHighScore);

console.log('\n7. unshift() - 开头添加');
const arr = [2, 3];
arr.unshift(1);
console.log('添加后:', arr);

console.log('\n8. splice() - 添加删除');
const colors = ['red', 'green', 'blue'];
colors.splice(1, 1, 'yellow');
console.log('替换后:', colors);

console.log('\n9. sort() - 排序');
const sortedAsc = [...numbers].sort((a, b) => a - b);
const sortedDesc = [...numbers].sort((a, b) => b - a);
console.log('升序:', sortedAsc, '降序:', sortedDesc);

console.log('\n10. reduce() - 累加');
const sum = numbers.reduce((total, num) => total + num, 0);
console.log('数组求和:', sum);
