From 3fb996b9afc578dfe87e947582b3d8bb9cb6fd07 Mon Sep 17 00:00:00 2001 From: any Date: Fri, 13 Dec 2024 22:54:51 +0800 Subject: [PATCH] go to Chiang Mai --- codes/js/std/Array/add&delete.test.js | 40 +++++++++++++++ codes/js/std/Array/iterate.test.js | 67 +++++++++++++++++++++++++ codes/js/std/Array/modify.test.js | 49 ++++++++++++++++++ codes/js/std/Array/other.test.js | 66 ++++++++++++++++++++++++ codes/js/std/Array/query.test.js | 65 ++++++++++++++++++++++++ docs/.vitepress/sidebar/javascript.js | 38 +++++++------- docs/.vitepress/sidebar/js-std.js | 2 +- docs/upl/diff.md | 26 ++++++++++ docs/upl/index.md | 4 +- docs/upl/js-std/Array.md | 59 +++++++++++++++++----- docs/upl/js-std/TypedArrays.md | 6 ++- docs/upl/js-std/data-structure.md | 8 ++- docs/upl/js/paradigm/fp/behavior.md | 1 + docs/upl/js/paradigm/fp/closure.md | 1 + docs/upl/js/paradigm/fp/function.md | 1 + docs/upl/js/paradigm/fp/index.md | 1 + docs/upl/js/paradigm/fp/operational.md | 1 + docs/upl/js/paradigm/{ => oop}/index.md | 0 docs/upl/js/structure/declaration.md | 3 -- docs/upl/js/structure/element.md | 3 -- docs/upl/js/structure/organization.md | 3 -- docs/upl/js/structure/programming.md | 3 -- docs/upl/js/structure/segmentation.md | 3 -- 23 files changed, 395 insertions(+), 55 deletions(-) create mode 100644 codes/js/std/Array/add&delete.test.js create mode 100644 codes/js/std/Array/iterate.test.js create mode 100644 codes/js/std/Array/modify.test.js create mode 100644 codes/js/std/Array/other.test.js create mode 100644 codes/js/std/Array/query.test.js create mode 100644 docs/upl/diff.md create mode 100644 docs/upl/js/paradigm/fp/behavior.md create mode 100644 docs/upl/js/paradigm/fp/closure.md create mode 100644 docs/upl/js/paradigm/fp/function.md create mode 100644 docs/upl/js/paradigm/fp/index.md create mode 100644 docs/upl/js/paradigm/fp/operational.md rename docs/upl/js/paradigm/{ => oop}/index.md (100%) delete mode 100644 docs/upl/js/structure/declaration.md delete mode 100644 docs/upl/js/structure/element.md delete mode 100644 docs/upl/js/structure/organization.md delete mode 100644 docs/upl/js/structure/programming.md delete mode 100644 docs/upl/js/structure/segmentation.md diff --git a/codes/js/std/Array/add&delete.test.js b/codes/js/std/Array/add&delete.test.js new file mode 100644 index 0000000..0cb91ae --- /dev/null +++ b/codes/js/std/Array/add&delete.test.js @@ -0,0 +1,40 @@ +/** + * ===add=== + * push* 尾部位置 + * unshift* 头部位置 + * ===delete=== + * pop* 尾部位置 + * shift* 头部位置 + * arr.length = n 长度修改(可清空) + * ===特殊=== + * splice* 任意位置的删除与插入 + * toSpliced 函数式 splice 方法 + */ + +const { push, unshift, fill } = Array; + +test("push&unshift用法", () => { + const arr = []; + arr.push("end"); + arr.unshift("start"); + expect(arr[0]).toBe("start"); + expect(arr[arr.length - 1]).toBe("end"); +}); + +test("pop&shift用法", () => { + const arr = [1, 2, 3, 4, 5]; + arr.shift(); + arr.shift(); + arr.pop(); + arr.pop(); + expect(arr).toEqual([3]); + arr.length = 0; + expect(arr).toEqual([]); +}); + +test("toSpliced用法", () => { + const arr = [0, 1, 2, 3, 4, 5]; + const arr1 = arr.toSpliced(1, 3, "x", "y"); + expect(arr).toEqual([0, 1, 2, 3, 4, 5]); // 没变 + expect(arr1).toEqual([0, "x", "y", 4, 5]); // 首先删除 3 个元素,然后插入 2 个元素 +}); diff --git a/codes/js/std/Array/iterate.test.js b/codes/js/std/Array/iterate.test.js new file mode 100644 index 0000000..820da88 --- /dev/null +++ b/codes/js/std/Array/iterate.test.js @@ -0,0 +1,67 @@ +/** + * ===lang:iterate=== + * forEach 遍历 + * map 遍历返回新数组 + * every 遍历且所有项都通过测试 + * some 遍历且有项通过测试 + * filter 遍历且过滤数组 + * reduce/reduceRight 遍历且归因 + */ +const { forEach } = Array.prototype; +test("forEach是无法中途退出的全量迭代", () => { + const array = [1, 2, 3, 4, 5, 6]; + let value = 0; + array.forEach((item, index) => { + // js引擎不报错,jest报错 + // if(index === 1) continue; + // if(index === 2) break; + value++; + }); + expect(value).toBe(6); +}); +test("map是无法中途退出的全量迭代", () => { + const array = [1, 2, 3]; + const result = array.map((item) => item); + expect(result).toEqual([1, 2, 3]); +}); +test("every即每一轮都返回 true 则最终返回 true,遇false会终止迭代并返回 false", () => { + const arr = [1, 2, 3]; + let count = 0; + arr.every((item) => { + count++; + if (item === 2) return false; + return true; + }); + expect(count).toBe(2); +}); +test("some即只要有一轮返回 true 则最终返回 true,遇 true会终止迭代并返回 true", () => { + const arr = [1, 2, 3]; + let count = 0; + arr.some((item) => { + count++; + if (item === 2) return true; + return false; + }); + expect(count).toBe(2); +}); +test("filter即筛选,用法是遇false 则不返回,是中途无法退出的全量迭代,", () => { + const array = [1, 2, 3, 4, 5]; + let count = 0; + const result = array.filter((item) => { + count++; + return item < 3; + }); + expect(result).toEqual([1, 2]); + expect(count).toBe(5); +}); +test("reduce向左汇总,即遍历方向向右", () => { + const initialValue = 0; + const callbackFn = function (accumulator, currentValue, currentIndex, array) { + return Math.max(accumulator, currentValue); + }; + const arr = [10, 100]; + expect(arr.reduce(callbackFn, initialValue)).toBe(100); +}); +test("reduceRight向右汇总,即遍历方向向左", () => { + // TODO +}); diff --git a/codes/js/std/Array/modify.test.js b/codes/js/std/Array/modify.test.js new file mode 100644 index 0000000..2d4e494 --- /dev/null +++ b/codes/js/std/Array/modify.test.js @@ -0,0 +1,49 @@ +/** + * ===modify=== + * fill* 长度填充来改变元素值 + * copyWithin* 长度不变的选区覆盖 + * reverse* 序号反转,倒序 + * sort* 自定义排列顺序 + * toSorted 函数式 sort 方法 + */ +test("fill用法", () => { + const arr = []; + arr.length = 3; + arr.fill(0); // 第三个参数不写,默认值为arr.length + expect(arr).toEqual([0, 0, 0]); + arr.length = 6; + arr.fill(1, 3, arr.length); // 第二和第三个参数的用法,范围[index1,index2) + expect(arr).toEqual([0, 0, 0, 1, 1, 1]); +}); +test("copyWithin用法", () => { + const arr = [0, 1, 2, 3, 4, 5]; + expect(arr.copyWithin(4, 0, 3)).toEqual([0, 1, 2, 3, 0, 1]); + expect(arr.copyWithin(4, 0, 4)).toEqual([0, 1, 2, 3, 0, 1]); // 即使范围右值变化,数组长度不变 +}); +test("reverse用法", () => { + const arr = [0, 1, 2, 3]; + arr.reverse(); + expect(arr).toEqual([3, 2, 1, 0]); // 副作用方法 +}); +test("sort自定义排序。返回值为 false 就调换两者的位置", () => { + // 需求:根据年龄升序排序 + const users = [ + { name: "John", age: 30 }, + { name: "Jane", age: 25 }, + { name: "Doe", age: 28 }, + ]; + users.sort((a, b) => a.age - b.age); + expect(users[0].age).not.toBe(30); // 副作用方法 + expect(users[0].age).toBe(25); +}); +test("toSort,无副作用", () => { + // 需求:根据年龄升序排序 + const users = [ + { name: "John", age: 30 }, + { name: "Jane", age: 25 }, + { name: "Doe", age: 28 }, + ]; + const users2 = users.toSorted((a, b) => a.age - b.age); + expect(users[0].age).toBe(30); // 无副作用方法 + expect(users2[0].age).toBe(25); +}); diff --git a/codes/js/std/Array/other.test.js b/codes/js/std/Array/other.test.js new file mode 100644 index 0000000..e3f98b2 --- /dev/null +++ b/codes/js/std/Array/other.test.js @@ -0,0 +1,66 @@ +/** + * keys 返回iterator 对象 + * values 返回 iterator 对象 + * flat 数组降维 + * flatMap 高级数组降维,外层map里层 flat + * concat 合并数组(单层) + * join 转为字符串 + * entries 数据类型转换 + * Array.isArray(array) 是否为数组 + * Array.of(...elementN) 元素序列转数组 + * Array.from(arrayLike, [cb], [thisArg]) 类数组转数组 + * Array.fromAsync(arrayLike, [cb], [thisArg]) 同上的异步方法 + */ +test("keys&values用法", () => { + const arr = ["a", "b", "c"]; + const iterator = arr.values(); + let count = 0; + for (const value of iterator) { + expect(value).toBe(arr[count]); + count++; + } +}); +test("flat&flatmap用法", () => { + const arr = [1, [2, [3, [4]]]]; + arr.length = 5; + // flat会删除稀疏数组的空槽 + // flat不处理类数组的元素 + expect(arr.flat(Infinity)).toEqual([1, 2, 3, 4]); + // flatmap,即外层是map,里层是深度为 1的flat + const result = arr.flatMap((element, index, array) => element); + expect(result).toEqual([1, 2, [3, [4]]]); +}); +test("concat用法", () => { + const arr1 = [1, 2]; + const arr2 = [3, 4]; + expect(arr1.concat(arr2)).toEqual([1, 2, 3, 4]); +}); +test("join用法", () => { + const arr = [1, 2, 3]; + expect(arr.join(",")).toBe("1,2,3"); +}); +test("entries用法", () => { + const arr = ["a", "b", "c"]; + const entries = arr.entries(); + let count = 0; + for (const entry of entries) { + expect(entry).toEqual([count, arr[count]]); + count++; + } +}); +test("isArray用法", () => { + const arr = []; + expect(Array.isArray(arr)).toBeTruthy(); +}); +test("Array.of用法", () => { + expect(Array.of(1, 2, 3)).toEqual(Array(1, 2, 3)); // [1, 2, 3] + const arr = []; + arr.length = 3; + expect(arr).toEqual(Array(3)); // 两种空槽数组的产生 +}); +test("Array.from&fromAsync用法", () => { + // 应用于可迭代对象或者类数组对象 + // 可迭代对象:部署了object[Symbol.iterator] + // 类数组对象:拥有 length属性 和索引元素的对象 + // TODO +}); diff --git a/codes/js/std/Array/query.test.js b/codes/js/std/Array/query.test.js new file mode 100644 index 0000000..3465f33 --- /dev/null +++ b/codes/js/std/Array/query.test.js @@ -0,0 +1,65 @@ +/** + * ===query=== + * ---查位置--- + * findIndex/findLastIndex(callbackFn) 匹配的第一个/最后一个索引 + * indexOf/lastIndexOf(searchElement, fromIndex) 匹配的第一个/最后一个索引 + * ---查元素或集合--- + * includes 是否包含元素 + * find/findLast((element,index,array)=>{}) 匹配的第一个/最后一个元素值 + * at 按位置返回元素 + * with 替换一个元素 + * slice 范围切片 + */ +test("findIndex/findLastIndex用法", () => { + const arr = ["a", "b", "a"]; + function callbackFn(element, index, array) { + return element === "a"; + } + expect(arr.findIndex(callbackFn)).toBe(0); + expect(arr.findLastIndex(callbackFn)).toBe(2); +}); +test("indexOf/lastIndexOf用法", () => { + const arr = ["a", "b", "a"]; + expect(arr.indexOf("a")).toBe(0); + expect(arr.lastIndexOf("a")).toBe(2); +}); +test("includes用法", () => { + const arr = ["a", "b", "a"]; + expect(arr.includes("a")).toBeTruthy(); + expect(arr.includes("b")).toBeTruthy(); + expect(arr.includes("c")).not.toBeTruthy(); +}); +test("find/findLast用法", () => { + const arr = ["a", "b", "a"]; + let index1 = 0; + let index2 = 0; + arr.find((item, index) => { + index1 = index; + return item === "a"; + }); + arr.findLast((item, index) => { + index2 = index; + return item === "a"; + }); + expect([index1, index2]).toEqual([0, 2]); +}); +test("at用法,相比属性访问器可以使用负数取值", () => { + const arr = ["a", "b", "c"]; + // 第一个元素序号为 0,最后一个元素序号为-1,不对称。 + expect(arr.at(0)).toBe("a"); + expect(arr.at(2)).toBe("c"); + expect(arr.at(-1)).toBe("c"); + expect(arr.at(-2)).toBe("b"); +}); +test("with用法,替换一个元素值,返回密集数组", () => { + const arr = ["a", "b", "c"]; + expect(arr.with(0, "x")).toEqual(["x", "b", "c"]); + expect(arr.with(-1, "z")).toEqual(["a", "b", "z"]); +}); +test("slice用法,通常用来浅拷贝", () => { + const object = { name: "slice" }; + const arr = [object]; + const slicedArr = arr.slice(); // 浅拷贝 + object.name = "sliced"; // 修改对象 + expect(slicedArr[0]).toEqual(arr[0]); // 指针地址相同 +}); diff --git a/docs/.vitepress/sidebar/javascript.js b/docs/.vitepress/sidebar/javascript.js index b48845c..2c93fd9 100644 --- a/docs/.vitepress/sidebar/javascript.js +++ b/docs/.vitepress/sidebar/javascript.js @@ -33,31 +33,31 @@ export default { { text: "overview", link: "upl/js/structure" }, { text: "element", - link: "upl/js/structure/element", + // link: "upl/js/structure/element", }, { text: "declaration", - link: "upl/js/structure/declaration", + // link: "upl/js/structure/declaration", }, { text: "segmentation", - link: "upl/js/structure/segmentation", + // link: "upl/js/structure/segmentation", }, { text: "organization", - link: "upl/js/structure/organization", + // link: "upl/js/structure/organization", }, { text: "programming ", - link: "upl/js/structure/programming", + // link: "upl/js/structure/programming", }, { text: "scope", - link: "upl/js/structure/scope", + // link: "upl/js/structure/scope", }, { text: "private", - link: "upl/js/structure/private", + // link: "upl/js/structure/private", }, ], }, @@ -107,28 +107,28 @@ export default { collapsed: true, items: [ { - text: "Functional 函数式", + text: "Functional", collapsed: true, items: [ { - text: "overview 概况", - link: "upl/js/functional/overview/", + text: "overview", + link: "/upl/js/paradigm/fp", }, { - text: "从运算式语言到函数式语言", - link: "upl/js/functional/arithmeticToFunctional/", + text: "operational", + link: "/upl/js/paradigm/fp/operational", }, { - text: "function 函数", - link: "upl/js/functional/function/", + text: "function", + link: "/upl/js/paradigm/fp/function", }, { - text: "functionBehavior 函数行为", - link: "upl/js/functional/functionBehavior/", + text: "函数行为", + link: "/upl/js/paradigm/fp/behavior", }, { - text: "closure 闭包", - link: "upl/js/functional/closure/", + text: "closure", + link: "/upl/js/paradigm/fp/closure", }, ], }, @@ -186,7 +186,7 @@ export default { ], }, { - text: "Build-in Objects", + text: "Global Objects", collapsed: true, items: jsstd, }, diff --git a/docs/.vitepress/sidebar/js-std.js b/docs/.vitepress/sidebar/js-std.js index 1ee98b9..7ecbfb3 100644 --- a/docs/.vitepress/sidebar/js-std.js +++ b/docs/.vitepress/sidebar/js-std.js @@ -42,7 +42,7 @@ export default [ }, { text: "Keyed-Collections(键值集合)", - collapsed: false, + collapsed: true, items: [ { text: "Object", diff --git a/docs/upl/diff.md b/docs/upl/diff.md new file mode 100644 index 0000000..18a8875 --- /dev/null +++ b/docs/upl/diff.md @@ -0,0 +1,26 @@ +# 语言对比 + +## c 和 c++的对比 + + +| 分类 | 对比项 | C语言特性 | C++语言特性 | 备注 | +|------|------|-------|--------|--------| +| 语言基础 | 语言范式 | 过程式编程语言| 支持过程式编程和面向对象编程 | C++是C的超集,支持面向对象编程 | +| | 数据类型 | 基本数据类型、结构体、联合、枚举 | 基本数据类型、结构体、类、联合、枚举,还有引用类型(C++新增引用类型) | C++增加了类和引用类型 | +| | 函数 | 函数不能重载,无默认参数(C99开始支持函数的部分默认参数特性,但和C++的默认参数有区别) | 支持函数重载和默认参数 | C++允许函数名相同但参数列表不同 | +| 内存管理 | 动态内存分配 | 使用malloc/free进行动态内存分配| 使用new/delete进行动态内存分配(同时也可以使用malloc/free,但new/delete有类型安全和构造/析构函数调用等优势) | C++提供了更安全的内存管理方式 | +| 输入输出 | 输入输出库 | 使用stdio.h库(如printf, scanf) | 使用iostream库(如cin, cout) | C++的iostream库提供了更丰富的输入输出功能 | +| 面向对象 | 类和对象 | 没有类的概念,但可以通过结构体和函数指针等模拟简单的面向对象特性 | 支持类和对象,支持封装、继承和多态 | C++的核心特性之一 | +| | 继承 | 没有继承概念,但可以通过结构体嵌套等方式模拟部分继承功能 | 支持单继承和多继承 | 继承是面向对象编程的一个重要特性 | +| | 多态 |没有直接的多态概念,但可以通过函数指针实现简单的类似多态功能 | 支持多态,可以通过虚函数实现 | 多态是面向对象编程的一个重要特性 | +| 模板 | 模板机制 | 无 | 支持函数模板和类模板 | 模板提供了代码复用和泛型编程的能力 | +| 异常处理 | 异常处理 | 无异常处理机制 | 支持异常处理机制(try, catch, throw)| C++提供了异常处理机制 | +| 运算符重载 | 运算符重载 | 不支持运算符重载 | 支持运算符重载 | 运算符重载使得操作符可以用于用户定义的类型 | +| 名称空间 | 名称空间 | 无 | 支持名称空间,用于避免名称冲突 | 名称空间提供了更好的代码组织和管理方式 | +| 构造函数 | 构造函数 | 没有构造函数概念,但可以编写初始化函数来达到类似效果 | 支持构造函数和析构函数 | 构造函数用于初始化对象,析构函数用于清理资源 | +| 静态成员 | 静态成员 | 静态成员变量和函数,但不支持静态成员函数的内联定义 | 支持静态成员变量和函数,包括内联定义 | C++提供了更灵活的静态成员支持 | +| 友元 | 友元 | 支持友元概念 | 支持友元概念,包括友元类和友元函数 | 友元提供了访问私有和保护成员的能力 | +| 常量 | 常量 | 使用#define或const关键字声明常量 | 使用const关键字声明常量,支持更严格的类型检查 | C++的const关键字提供了更好的类型安全 | +| 类型转换 | 类型转换 | 使用类型转换运算符如(int)a | 使用类型转换运算符如static_cast(b)等 | C++提供了更安全的类型转换机制 | +| 宏 | 宏定义 | 预处理器宏,功能有限 | 预处理器宏,功能有限,但C++支持更复杂的宏定义(C++中宏的使用场景相对C有所减少,因为有更多其他特性可替代部分宏功能) | C++宏定义可以更复杂 | +| 标准库 | 标准库 | 标准库较小,主要包含一些基本的函数和工具 | 标准模板库(STL)提供了丰富的数据结构和算法 | C++的标准库比C更丰富| diff --git a/docs/upl/index.md b/docs/upl/index.md index 635f256..f66a81e 100644 --- a/docs/upl/index.md +++ b/docs/upl/index.md @@ -2,8 +2,8 @@ ## 通用编程语言对比 -| 特点\语言 | C | Rust | JavaScript | TypeScript | -| --------- | -------------------------------- | ---------------------------- | ---------------------------- | ----------------------- | +| 特点\语言 | C | Rust | JavaScript | TypeScript | Python | +| --------- | -------------------------------- | ---------------------------- | ---------------------------- | ----------------------- | ------ | | overview | 静态、强类型、编译 | 静态、强类型、编译,内存安全 | 动态、弱类型、解释 | 动态、强类型、编译+解释 | | scene | 系统、嵌入式领域、信息类竞赛 | 系统、嵌入式领域、前端工程 | web,应用开发 | web,类库开发 | | public | 1972,丹尼斯·里奇,贝尔实验室 | 2010,Mozilla 研究院 | 1995,Brendan Eich,Netscape | 2012,微软 | diff --git a/docs/upl/js-std/Array.md b/docs/upl/js-std/Array.md index 548672a..044cf6b 100644 --- a/docs/upl/js-std/Array.md +++ b/docs/upl/js-std/Array.md @@ -19,10 +19,12 @@ Array(2); // [undefined,undefined] arr.length; // 2 ``` -## Prototype +## Prototype & Static 以下方法来自于原型对象 Array.prototype +增删改 + ecma| api |describe |note | --- | --- | --- | --- | @@ -33,11 +35,22 @@ ecma| api |describe |note | 5|splice(start,count,...itemN) [:boom:]|删除选择元素,然后在此位置添加新元素| 2023|toSpliced(start,count,...itemN)|返回新数组,其中剔除了选择元素、添加了新元素| 2015|fill(item,[start,[end]]) [:boom:]|按索引范围填充(替换)数组成员| +2015|copyWithin(target, start, [end]) [:boom:]|在数组内部进行复制操作| 5|reverse() [:boom:]|反转数组中的元素顺序| 5|sort([cb]) [:boom:]|对数组元素进行排序| 2023|toSorted([cb])|返回排序后的数组,是 sort 方法的改进版| -2015|copyWithin(target, start, [end]) [:boom:]|在数组内部进行复制操作| -2023|with(index,item)|返回新数组,选中元素将被新元素替代| + +::: details exercises +::: code-group +<<< @/../codes/js/std/Array/add&delete.test.js [add&delete] +<<< @/../codes/js/std/Array/modify.test.js [modify] +::: + +遍历 + + +ecma| api |describe |note | +--- | --- | --- | --- | 5|forEach(cb,[thisArg])|遍历数组中的每个元素,通过执行回调| 5|map(cb,[thisArg])|遍历数组中的每个元素,返回一个新数组(每轮的返回值)| 5|every(cb,[thisArg])|测试数组中所有元素是否都通过由提供的函数实现的测试| @@ -45,6 +58,17 @@ ecma| api |describe |note | 5|filter(cb,[thisArg])|返回数组,成员通过了测试| 5|reduce(cb, [initialValue])|对数组中的每个元素执行 reduce 操作(从左到右),将其结果进行汇总| 5|reduceRight(cb, [initialValue])|对数组中的每个元素执行 reduce 操作(从右到左),将其结果进行汇总| + +::: details exercises +::: code-group +<<< @/../codes/js/std/Array/iterate.test.js [iterate] +::: + +检索位置和元素 + + +ecma| api |describe |note | +--- | --- | --- | --- | 2015|find(cb, [thisArg])|返回数组中满足提供的测试函数的第一个元素的值,否则返回 undefined| 2015|findIndex(cb, [thisArg])|返回数组中满足提供的测试函数的第一个元素的索引,否则返回-1| 2022|findLast(cb, [thisArg])|返回数组中满足提供的测试函数的最后一个元素的值,否则返回 undefined| @@ -52,10 +76,22 @@ ecma| api |describe |note | 2022|at(index)|返回数组中指定位置的元素|index 可以是负数| 5|indexOf(searchElement, [fromIndex])|返回在数组中可以找到一个给定元素的第一个索引,如果不存在,则返回-1| 5|lastIndexOf(searchElement, [fromIndex])|返回在数组中可以找到一个给定元素的最后一个索引,如果不存在,则返回-1| +5|slice([start], [end])|返回一个新数组,包含从开始到结束(不包括结束)选择的数组的一部分| + +::: details exercises +::: code-group +<<< @/../codes/js/std/Array/query.test.js [query] +::: + +其他工具 + + +ecma| api |describe |note | +--- | --- | --- | --- | +2023|with(index,item)|返回新数组,选中元素将被新元素替代| 2016|includes(searchElement, [fromIndex])|判断数组是否包含某个元素| 5|join([separator])|将数组中的所有元素连接成一个字符串| 5|concat(...valueN)|返回合并成员后的数组| -5|slice([start], [end])|返回一个新数组,包含从开始到结束(不包括结束)选择的数组的一部分| 2015|keys()|返回一个新的 Array Iterator 对象,包含数组中每个索引的键| 2015|values()|返回一个新的 Array Iterator 对象,包含数组中每个索引的值| 2015|entries()|返回一个新的 Array Iterator 对象,包含数组中每个索引的键值对| @@ -64,15 +100,14 @@ ecma| api |describe |note | 5|toLocaleString()|返回一个表示数组的字符串,使用当前的地区设置的语言| 5|toString()|返回一个表示数组及其元素的字符串| 2015|\[Symbol.iterator]()|返回一个新的 Array Iterator 对象,该对象包含数组中每个索引的值| - - - -## Static - - -ecma| api |describe |note | ---- | --- | --- | --- | 2015|Array.from(arrayLike, [cb], [thisArg])|参考可迭代对象,返回一个新的 Array 实例,在迭代中执行cb| 2015|Array.fromAsync(arrayLike, [cb], [thisArg])|参考异步可迭代对象,返回一个新的Array实例,在迭代中执行cb| 5|Array.isArray(array)|确定传递的值是否是一个数组| 2015|Array.of(...elementN)|由可变数量的变量,返回一个新的Array实例 + + + +::: details exercises +::: code-group +<<< @/../codes/js/std/Array/other.test.js [other] +::: diff --git a/docs/upl/js-std/TypedArrays.md b/docs/upl/js-std/TypedArrays.md index 88f13f3..dfe87ec 100644 --- a/docs/upl/js-std/TypedArrays.md +++ b/docs/upl/js-std/TypedArrays.md @@ -1,6 +1,10 @@ # typed arrays -[参考](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Typed_arrays) +参考 + +- https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Typed_arrays +- https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/TypedArray +- https://web.dev/articles/webgl-typed-arrays?hl=zh-cn ## 概念 diff --git a/docs/upl/js-std/data-structure.md b/docs/upl/js-std/data-structure.md index bd986b9..4b5059e 100644 --- a/docs/upl/js-std/data-structure.md +++ b/docs/upl/js-std/data-structure.md @@ -2,7 +2,7 @@ ## Descriptor -属性描述符.用来描述对象实例的一个属性。 +属性描述符,用来描述对象实例的一个属性。 数据结构: @@ -25,8 +25,8 @@ 默认值: -- 当对象以字面量定义时,属性的这 4 个默认值全为 true -- 当对象以属性描述符定义时,属性的(未定义值)默认值都是 false +- 当对象以字面量定义时,所有属性值都是 true +- 当对象以属性描述符定义时,未定义的属性值都是 false ## Descriptors @@ -57,5 +57,3 @@ ... ] ``` - -## 。。 diff --git a/docs/upl/js/paradigm/fp/behavior.md b/docs/upl/js/paradigm/fp/behavior.md new file mode 100644 index 0000000..8c88b6a --- /dev/null +++ b/docs/upl/js/paradigm/fp/behavior.md @@ -0,0 +1 @@ +# 函数的行为 diff --git a/docs/upl/js/paradigm/fp/closure.md b/docs/upl/js/paradigm/fp/closure.md new file mode 100644 index 0000000..05ae5e0 --- /dev/null +++ b/docs/upl/js/paradigm/fp/closure.md @@ -0,0 +1 @@ +# 闭包 diff --git a/docs/upl/js/paradigm/fp/function.md b/docs/upl/js/paradigm/fp/function.md new file mode 100644 index 0000000..fb9369a --- /dev/null +++ b/docs/upl/js/paradigm/fp/function.md @@ -0,0 +1 @@ +# 函数 diff --git a/docs/upl/js/paradigm/fp/index.md b/docs/upl/js/paradigm/fp/index.md new file mode 100644 index 0000000..95de28a --- /dev/null +++ b/docs/upl/js/paradigm/fp/index.md @@ -0,0 +1 @@ +# 函数式 diff --git a/docs/upl/js/paradigm/fp/operational.md b/docs/upl/js/paradigm/fp/operational.md new file mode 100644 index 0000000..9572e53 --- /dev/null +++ b/docs/upl/js/paradigm/fp/operational.md @@ -0,0 +1 @@ +# 从运算式语言到函数式语言 diff --git a/docs/upl/js/paradigm/index.md b/docs/upl/js/paradigm/oop/index.md similarity index 100% rename from docs/upl/js/paradigm/index.md rename to docs/upl/js/paradigm/oop/index.md diff --git a/docs/upl/js/structure/declaration.md b/docs/upl/js/structure/declaration.md deleted file mode 100644 index 0273c13..0000000 --- a/docs/upl/js/structure/declaration.md +++ /dev/null @@ -1,3 +0,0 @@ -# 声明 - -TODO diff --git a/docs/upl/js/structure/element.md b/docs/upl/js/structure/element.md deleted file mode 100644 index feb6d28..0000000 --- a/docs/upl/js/structure/element.md +++ /dev/null @@ -1,3 +0,0 @@ -# 基本的组织元素 - -TODO diff --git a/docs/upl/js/structure/organization.md b/docs/upl/js/structure/organization.md deleted file mode 100644 index 77dbb98..0000000 --- a/docs/upl/js/structure/organization.md +++ /dev/null @@ -1,3 +0,0 @@ -# 组织形式分块的方法 - -TODO diff --git a/docs/upl/js/structure/programming.md b/docs/upl/js/structure/programming.md deleted file mode 100644 index d015eaa..0000000 --- a/docs/upl/js/structure/programming.md +++ /dev/null @@ -1,3 +0,0 @@ -# 层次结构程序设计 - -TODO diff --git a/docs/upl/js/structure/segmentation.md b/docs/upl/js/structure/segmentation.md deleted file mode 100644 index 9f6a1e0..0000000 --- a/docs/upl/js/structure/segmentation.md +++ /dev/null @@ -1,3 +0,0 @@ -# 语句与代码分块 - -TODO