diff --git "a/\345\217\262\345\256\227\347\203\201/20251229-mvc\350\256\276\350\256\241\346\250\241\345\274\217.md" "b/\345\217\262\345\256\227\347\203\201/20251229-mvc\350\256\276\350\256\241\346\250\241\345\274\217.md" new file mode 100644 index 0000000000000000000000000000000000000000..16a0b108a069ff5db64323e6cfe0b24a26adafac --- /dev/null +++ "b/\345\217\262\345\256\227\347\203\201/20251229-mvc\350\256\276\350\256\241\346\250\241\345\274\217.md" @@ -0,0 +1,83 @@ +## 笔记 +设计模式类型 +```bash +- 创建型模式 +-- 工厂模式(Factory Pattern) +-- 抽象工厂模式(Abstract Factory Pattern) +-- 单例模式(Singleton Pattern) +-- 建造者模式(Builder Pattern) +-- 原型模式(Prototype Pattern) +``` +## 练习 + +第一题 +```js +for (let i = 1; i <= 9; i++) { + let row = ""; + for (let j = 1; j <= i; j++) { + row += j + "*" + i + "=" + (i * j) + " "; + } + console.log(row); +} + +``` + +第二题 +```js + +let age = 18; +let status; +status = age >= 18 ? '成年' : '未成年'; +if (age >= 18) { + status = '成年'; +} else { + status = '未成年'; +} + +``` + + +第三题 +```js + +let target = Math.floor(Math.random() * 100) + 1; +let guess = 50; + +if (guess > target) { + console.log("太大"); +} else if (guess < target) { + console.log("太小"); +} else { + console.log("猜对了"); +} + +``` + +第四题 +```js +function findDuplicates(arr) { + let duplicates = []; + for (let i = 0; i < arr.length; i++) { + if (arr.indexOf(arr[i], i + 1) !== -1 && duplicates.indexOf(arr[i]) === -1) { + duplicates.push(arr[i]); + } + } + return duplicates; +} +console.log(findDuplicates([1, 2, 4, 4, 3, 3, 1, 5, 3])); + +``` + +第五题 +```js + +function countOccurrences(arr, item) { + let count = 0; + for (let x of arr) { + if (x === item) count++; + } + return count; +} +console.log(countOccurrences([1, 2, 4, 4, 3, 4, 3], 4)); + +``` \ No newline at end of file diff --git "a/\345\217\262\345\256\227\347\203\201/20251231-mvc\346\216\247\345\210\266\345\231\250.md" "b/\345\217\262\345\256\227\347\203\201/20251231-mvc\346\216\247\345\210\266\345\231\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..64ce72e84d0881f1b5aa516bfb5663a9738e8d8a --- /dev/null +++ "b/\345\217\262\345\256\227\347\203\201/20251231-mvc\346\216\247\345\210\266\345\231\250.md" @@ -0,0 +1,66 @@ +## 笔记 +mvc控制器简介 +```bash +MVC 控制器负责响应针对 ASP.NET MVC 网站发出的请求。 每个浏览器请求都映射到特定的控制器。 +``` +mvc控制器操作 +```bash +控制器公开控制器操作。 操作是控制器上的一种方法,当你在浏览器地址栏中输入特定 URL 时,将调用该方法。 +``` +## 练习 + +第一题 +```js + +function mergeArrays(arr1, arr2) { + return arr1.concat(arr2); +} +console.log(mergeArrays([1, 2, 3, 4], ['a', 'b', 'c', 1])); + +``` + +第二题 +```js + +const numbersToSum = [10, 20, 30, 40, 50]; +const totalSum = numbersToSum.reduce((acc, curr) => acc + curr, 0); +console.log(totalSum); + +``` + +第三题 +```js + +const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]; +const odds = nums.filter(num => num % 2 !== 0); +console.log(odds); + +``` + +第四题 + +```js + +const students = [ + {name: "小明", score: 85}, + {name: "小红", score: 55}, + {name: "小刚", score: 90} +]; + +const passNames = students + .filter(s => s.score >= 60) + .map(s => s.name); + +console.log(passNames); + +``` + +第五题 +```js + +function removeItem(arr, item) { + return arr.filter(x => x !== item); +} +console.log(removeItem([1, 2, 3, 4, 2, 5], 2)); + +``` \ No newline at end of file diff --git "a/\345\217\262\345\256\227\347\203\201/20260104-mvc\350\267\257\347\224\261.md" "b/\345\217\262\345\256\227\347\203\201/20260104-mvc\350\267\257\347\224\261.md" new file mode 100644 index 0000000000000000000000000000000000000000..0e68671311e267c46b32a9293901f72ea07b3058 --- /dev/null +++ "b/\345\217\262\345\256\227\347\203\201/20260104-mvc\350\267\257\347\224\261.md" @@ -0,0 +1,58 @@ +## 笔记 +自定义路由 +```bash +自定义路由将传入请求映射到名为 Archive 的控制器,并调用 Entry () 操作。调用 Entry () 方法时,输入日期将作为名为 entryDate 的参数传递。 +``` +路由约束 +```bash +使用路由约束来限制与特定路由匹配的浏览器请求。 可以使用正则表达式来指定路由约束。 + +定义路由时,可以使用约束来限制与路由匹配的 URL。 +``` +## 练习 + +第一题 +```js +const originArr = [1, 2, 3, 4, 5]; +const doubled = originArr.map(num => num * 2); +console.log(doubled); + +``` +第二题 +```js + +function sumToN(n) { + let sum = 0; + for (let i = 1; i <= n; i++) { + sum += i; + } + return sum; +} + +console.log(sumToN(100)); + + +``` + +第三题 + +```js + +let myNaN = NaN; + +console.log(`NaN === NaN // ${myNaN === myNaN}`); +console.log(`isNaN(NaN) // ${isNaN(myNaN)}`); +console.log(`Number.isNaN(NaN) // ${Number.isNaN(myNaN)}`); + +``` + +第四题 +```js + +let res1 = +"123"; +let res2 = -"45"; +let res3 = !!"hello"; +console.log(`${res1}, ${res2}, ${res3}`); + +``` +