بتل کد Battle Codeدارد باز می‌شود…

The To-do List چالش 6 از جلسه‌ی 29، سخت

شکل Task یک کار است. دو تابع از صفر بنویس:
- create یک کار تازه بدون id می‌گیرد (Omit<Task, "id">) و یک Task کامل برمی‌گرداند. id را از nextId بگیر و بعد nextId را یکی زیاد کن.
- edit یک Task و چند تغییر (Partial<Task>) می‌گیرد و یک Task تازه برمی‌گرداند: { ...task, ...changes }. کارِ قدیمی عوض نمی‌شود.
خط‌های پایین کد را نگه دار. برنامه باید این سه خط را نشان بدهد:
1 Math false
1 Math true
2 Read

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
#out { direction: ltr; text-align: left; font: 16px monospace; margin: 12px 0; padding: 12px; min-height: 28px; border-radius: 12px; background: #0f172a; color: #e2e8f0; white-space: pre-wrap; overflow-wrap: anywhere; }
#out .line { min-height: 22px; }
</style>

<pre id="out"></pre>

<script type="text/typescript">
interface Task {
  id: number;
  title: string;
  done: boolean;
}

let nextId: number = 1;

// write create and edit here

const math = create({ title: "Math", done: false });
const mathDone = edit(math, { done: true });
const read = create({ title: "Read", done: false });
show(math.id, math.title, math.done);
show(mathDone.id, mathDone.title, mathDone.done);
show(read.id, read.title);
</script>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 29: ابزارهای آماده

بیشتر بخوان: جاوااسکریپت چیست؟ از دکمه‌ی وب تا Node.js