布丁撞奶茶 7 bulan lalu
induk
melakukan
b43d2dee03

+ 34 - 0
s202226701012/workspace/tslearn/classob.ts

@@ -0,0 +1,34 @@
+//类
+class studentClass {
+  name: string;
+  age: number;
+  isChecked: boolean = false;
+  constructor(studentDate: StudentInt) {}
+}
+//学生进入班级
+let studentList2: Array<{ name: string; age: number; isChecked?: boolean }> = [
+  { name: "xiaoming", age: 18, isChecked: true },
+  { name: "xiaowang", age: 18, isChecked: true },
+  { name: "zhangsan", age: 19, isChecked: false },
+  { name: "lisi", age: 20, isChecked: true },
+  { name: "wangwu", age: 21, isChecked: false },
+  { name: "zhaoliu", age: 22, isChecked: true },
+  { name: "sunqi", age: 23, isChecked: false },
+  { name: "zhouba", age: 24, isChecked: true },
+  { name: "wugeng", age: 25, isChecked: false },
+  { name: "zhengshi", age: 26, isChecked: true },
+  { name: "qianjiu", age: 27, isChecked: false },
+  { name: "housan", age: 28, isChecked: true },
+  { name: "yisi", age: 29, isChecked: false },
+  { name: "wuyu", age: 30, isChecked: true },
+  { name: "liuqi", age: 31, isChecked: false },
+  { name: "qianba", age: 32, isChecked: true },
+  { name: "jiusi", age: 33, isChecked: false },
+  { name: "shiwu", age: 34, isChecked: true },
+  { name: "eryou", age: 35, isChecked: false },
+];
+
+//学生打卡签到
+//findIndex的定义是找出数组的第一个满足测试函数的元素索引
+let idx = studentList2.findIndex((student) => (student.name = "wuyu"));
+studentList2[idx].isChecked = true;

+ 57 - 0
s202226701012/workspace/tslearn/datetype.js

@@ -0,0 +1,57 @@
+//string
+var studentName = "xiaoming";
+//number
+var studentAge = 18;
+//Boolean
+var isChecked = true;
+//Date
+var now = new Date();
+//Array
+var studentList1 = [
+    { name: "xiaoming", age: 18 },
+    { name: "xiaowang'", age: 18, isChecked: true },
+];
+var studentnew = {
+    name: "xiaoming",
+    age: 18,
+    isChecked: false,
+    works: ["yuwen"],
+};
+studentList1.push(studentnew);
+var task1 = { progress: 1, complete: true, errorMsg: "youwenti" };
+/**
+ * 统计人数 没有接口表示
+ * @param studentList{Array<StudentInt}  学生列表
+ * @returns
+ */
+function checkCount1(studentList) {
+    // let checkList = studentList.map(item=>item.isChecked ? 1:0)
+    // let count = 0;
+    // checkList.forEach(check=>{
+    //   if(check==1)
+    //     count ++
+    // })
+    var checkList = studentList.map(function (item) { return (item.isChecked ? 1 : 0); });
+    var count = 0;
+    checkList.forEach(function (checked) {
+        if (checked == 1)
+            count++;
+    });
+    return count;
+}
+/**
+ * 统计人数 用函数接口表示
+ * @param studentList{Array<StudentInt}  学生列表
+ * @returns
+ */
+var checkCount = function (studentList) {
+    var checkList = studentList.map(function (item) { return (item.isChecked ? 1 : 0); });
+    var count = 0;
+    checkList.forEach(function (checked) {
+        if (checked === 1)
+            count++;
+    });
+    return count;
+};
+var count = checkCount(studentList1);
+console.log(count);

+ 67 - 1
s202226701012/workspace/tslearn/datetype.ts

@@ -10,13 +10,79 @@ let isChecked: Boolean = true;
 //Date
 let now: Date = new Date();
 
+//定义接口
+interface StudentInt {
+  name: string;
+  age: number;
+  isChecked?: boolean;
+  works?: Array<string>;
+}
+
+//定义函数接口
+interface CheckCountFunction {
+  (studentList: Array<StudentInt>): number;
+}
+
 //Array
 let studentList1: Array<{ name: string; age: number; isChecked?: boolean }> = [
   { name: "xiaoming", age: 18 },
+  { name: "xiaowang'", age: 18, isChecked: true },
 ];
-let studentnew = {
+
+let studentnew: StudentInt = {
   name: "xiaoming",
   age: 18,
   isChecked: false,
   works: ["yuwen"],
 };
+studentList1.push(studentnew);
+
+/**接口:实现提示词检索
+ * @param progress {number} 任务进度
+ * @param complete {boolean} 任务是否完成
+ * @param errorMsg {string} 错误信息
+ */
+interface AgentTask {
+  progress: number; //任务进度
+  complete: boolean; //任务是否完成
+  errorMsg: string; //错误信息
+}
+
+let task1: AgentTask = { progress: 1, complete: true, errorMsg: "youwenti" };
+
+/**
+ * 统计人数 没有接口表示
+ * @param studentList{Array<StudentInt}  学生列表
+ * @returns
+ */
+function checkCount1(studentList: Array<StudentInt>): number {
+  // let checkList = studentList.map(item=>item.isChecked ? 1:0)
+  // let count = 0;
+  // checkList.forEach(check=>{
+  //   if(check==1)
+  //     count ++
+  // })
+  let checkList = studentList.map((item): 1 | 0 => (item.isChecked ? 1 : 0));
+  let count = 0;
+  checkList.forEach((checked) => {
+    if (checked == 1) count++;
+  });
+  return count;
+}
+/**
+ * 统计人数 用函数接口表示
+ * @param studentList{Array<StudentInt}  学生列表
+ * @returns
+ */
+const checkCount: CheckCountFunction = (
+  studentList: Array<StudentInt>
+): number => {
+  let checkList = studentList.map((item): 1 | 0 => (item.isChecked ? 1 : 0));
+  let count = 0;
+  checkList.forEach((checked) => {
+    if (checked === 1) count++;
+  });
+  return count;
+};
+let count = checkCount(studentList1);
+console.log(count);