دوّر على مدينة
البيانات التجريبية هي data (arrayمصفوفةتُنطق أَرَايقايمة من القيم بترتيب، كل واحدة ليها رقم مكان بيبدأ من صفر. من { city, temp }). اكتب findCity(data, name) بترجّع السجل بتاع المدينة، أو null لو مش موجودة.
const data = [
{ city: 'القاهرة', temp: 34 },
{ city: 'الإسكندرية', temp: 28 },
{ city: 'أسوان', temp: 41 },
{ city: 'السويس', temp: 18 },
];
function findCity(data, name) {
// اكتب هنا
}
نسّق السطر
اكتب format(record) بترجّع المدينة: الدرجة°م، مثلًا القاهرة: 34°م.
const data = [
{ city: 'القاهرة', temp: 34 },
{ city: 'الإسكندرية', temp: 28 },
{ city: 'أسوان', temp: 41 },
{ city: 'السويس', temp: 18 },
];
function findCity(data, name) {
return data.find((d) => d.city === name) ?? null;
}
function format(record) {
// اكتب هنا
}
المتوسط
اكتب average(data) بترجّع متوسط الحرارة مقرّب لرقم عشري واحد (مثلًا 30.3).
const data = [
{ city: 'القاهرة', temp: 34 },
{ city: 'الإسكندرية', temp: 28 },
{ city: 'أسوان', temp: 41 },
{ city: 'السويس', temp: 18 },
];
function findCity(data, name) {
return data.find((d) => d.city === name) ?? null;
}
function format(record) {
return `${record.city}: ${record.temp}°م`;
}
function average(data) {
// اكتب هنا
}
وصف الجو
اكتب feel(temp): من 35 'حر'، من 20 لأقل من 35 'معتدل'، وأقل من 20 'برد'.
const data = [
{ city: 'القاهرة', temp: 34 },
{ city: 'الإسكندرية', temp: 28 },
{ city: 'أسوان', temp: 41 },
{ city: 'السويس', temp: 18 },
];
function findCity(data, name) {
return data.find((d) => d.city === name) ?? null;
}
function format(record) {
return `${record.city}: ${record.temp}°م`;
}
function average(data) {
const sum = data.reduce((s, d) => s + d.temp, 0);
return Math.round((sum / data.length) * 10) / 10;
}
function feel(temp) {
// اكتب هنا
}
التقرير مرتّب
اكتب report(data) بترجّع arrayمصفوفةتُنطق أَرَايقايمة من القيم بترتيب، كل واحدة ليها رقم مكان بيبدأ من صفر. من نصوص المدينة: الدرجة°م (الوصف) مرتّبة من الأسخن للأبرد، من غير ما تعدّل data. استخدم format وfeel.
const data = [
{ city: 'القاهرة', temp: 34 },
{ city: 'الإسكندرية', temp: 28 },
{ city: 'أسوان', temp: 41 },
{ city: 'السويس', temp: 18 },
];
function findCity(data, name) {
return data.find((d) => d.city === name) ?? null;
}
function format(record) {
return `${record.city}: ${record.temp}°م`;
}
function average(data) {
const sum = data.reduce((s, d) => s + d.temp, 0);
return Math.round((sum / data.length) * 10) / 10;
}
function feel(temp) {
if (temp >= 35) return 'حر';
if (temp >= 20) return 'معتدل';
return 'برد';
}
function report(data) {
// اكتب هنا
}