المسارات / مشاريع / قائمة المهام

قائمة المهام

ابنِ منطق تطبيق مهام كامل: إضافة، تبديل الحالة، حذف، إحصائيات وفلترة. كله فنكشنز نقية من غير ما تعدّل الأصل.

مبتدئ35 دقيقةاتحلّ 0 من 5
الخطوة 1

أضف مهمة

اكتب addTodo(list, text) بترجّع جديدة فيها كل المهام القديمة ومهمة جديدة { id, text, done: false }. الـ id هو رقم أكبر من أكبر id موجود (يبدأ من 1). الـ الأصلية ميتغيّرش فيها حاجة.

function addTodo(list, text) {
  // اكتب هنا
}
الخطوة 2

بدّل الحالة

اكتب toggleTodo(list, id) بترجّع جديدة فيها المهمة دي معكوسة الحالة (done)، وباقي المهام زي ما هي.

function addTodo(list, text) {
  const id = list.reduce((m, t) => Math.max(m, t.id), 0) + 1;
  return [...list, { id, text, done: false }];
}

function toggleTodo(list, id) {
  // اكتب هنا
}
الخطوة 3

احذف مهمة

اكتب removeTodo(list, id) بترجّع جديدة من غير المهمة دي.

function addTodo(list, text) {
  const id = list.reduce((m, t) => Math.max(m, t.id), 0) + 1;
  return [...list, { id, text, done: false }];
}

function toggleTodo(list, id) {
  return list.map((t) => (t.id === id ? { ...t, done: !t.done } : t));
}

function removeTodo(list, id) {
  // اكتب هنا
}
الخطوة 4

إحصائيات

اكتب stats(list) بترجّع { total, done, left }: العدد الكلي، المنجز، والمتبقي.

function addTodo(list, text) {
  const id = list.reduce((m, t) => Math.max(m, t.id), 0) + 1;
  return [...list, { id, text, done: false }];
}

function toggleTodo(list, id) {
  return list.map((t) => (t.id === id ? { ...t, done: !t.done } : t));
}

function removeTodo(list, id) {
  return list.filter((t) => t.id !== id);
}

function stats(list) {
  // اكتب هنا
}
الخطوة 5

فلترة

اكتب visible(list, mode): لو mode هي 'done' ترجّع المنجز بس، و'left' المتبقي بس، وأي حاجة تانية ترجّع الكل.

function addTodo(list, text) {
  const id = list.reduce((m, t) => Math.max(m, t.id), 0) + 1;
  return [...list, { id, text, done: false }];
}

function toggleTodo(list, id) {
  return list.map((t) => (t.id === id ? { ...t, done: !t.done } : t));
}

function removeTodo(list, id) {
  return list.filter((t) => t.id !== id);
}

function stats(list) {
  const done = list.filter((t) => t.done).length;
  return { total: list.length, done, left: list.length - done };
}

function visible(list, mode) {
  // اكتب هنا
}
برهان

الدروس

اتحلّ 0 من 174 تمرين