Skip to content

Commit

Permalink
doc: updated chinese docs
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakshrma committed Mar 31, 2024
1 parent 90d54af commit 472ed5a
Showing 48 changed files with 707 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ tags: [math, array, beginner]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: Implementation of "accumulate" in typescript, javascript and deno.
description: 在 TypeScript、JavaScript 和 Deno 中实现 "accumulate" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

2 changes: 1 addition & 1 deletion i18n/zh/docusaurus-plugin-content-docs/current/all.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ tags: [array, function, beginner]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: Implementation of "all" in typescript, javascript and deno.
description: 在 TypeScript、JavaScript 和 Deno 中实现 "all" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

2 changes: 1 addition & 1 deletion i18n/zh/docusaurus-plugin-content-docs/current/allEqual.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ tags: [array, function, beginner]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: Implementation of "AllEqual" in typescript, javascript and deno.
description: 在 TypeScript、JavaScript 和 Deno 中实现 "AllEqual" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

32 changes: 32 additions & 0 deletions i18n/zh/docusaurus-plugin-content-docs/current/bifurcate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: bifurcate
tags: [array, intermediate]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: 在 TypeScript、JavaScript 和 Deno 中实现 "bifurcate" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

![TS](https://img.shields.io/badge/supports-typescript-blue.svg?style=flat-square)
![JS](https://img.shields.io/badge/supports-javascript-yellow.svg?style=flat-square)
![Deno](https://img.shields.io/badge/supports-deno-green.svg?style=flat-square)

将值分成两组。如果 `filter` 中的元素为真值,则集合中对应的元素属于第一组;否则,它属于第二组。

使用 `Array.prototype.reduce()``Array.prototype.push()` 根据 `filter` 将元素添加到组中。

```ts title="typescript"
const bifurcate = <T = any>(arr: T[], filter: boolean[]) =>
arr.reduce(
(acc, val, i) => {
acc[filter[i] ? 0 : 1].push(val);
return acc;
},
[[] as T[], [] as T[]]
);
```

```ts title="typescript"
bifurcate(["beep", "boop", "foo", "bar"], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ]
```
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ tags: [string, array, intermediate]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: Implementation of "capitalize" in typescript, javascript and deno.
description: 在 TypeScript、JavaScript 和 Deno 中实现 "capitalize" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ tags: [string, regexp, intermediate]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: Implementation of "capitalizeEveryWord" in typescript, javascript and deno.
description: 在 TypeScript、JavaScript 和 Deno 中实现 "capitalizeEveryWord" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

2 changes: 1 addition & 1 deletion i18n/zh/docusaurus-plugin-content-docs/current/chunk.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ tags: [array, intermediate]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: Implementation of "chunk" in typescript, javascript and deno.
description: 在 TypeScript、JavaScript 和 Deno 中实现 "chunk" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

55 changes: 55 additions & 0 deletions i18n/zh/docusaurus-plugin-content-docs/current/colorize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: colorize [给文本着色]
tags: [node, string, intermediate]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: 在 TypeScript、JavaScript 和 Deno 中实现 "colorize" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

![TS](https://img.shields.io/badge/supports-typescript-blue.svg?style=flat-square)
![JS](https://img.shields.io/badge/supports-nodejs-yellow.svg?style=flat-square)
![Deno](https://img.shields.io/badge/supports-deno-green.svg?style=flat-square)

在控制台中添加特殊字符到文本中以彩色打印(与 `console.log()` 结合使用)。

使用模板文字和特殊字符为字符串输出添加适当的颜色代码。
对于背景颜色,添加一个在字符串末尾重置背景颜色的特殊字符。

```ts title="typescript"
export const colorize = new (class {
color = (code: number, ended = false, ...messages: any[]) =>
`\x1b[${code}m${messages.join(" ")}${ended ? "\x1b[0m" : ""}`;
black = this.color.bind(null, 30, false);
red = this.color.bind(null, 31, false);
green = this.color.bind(null, 32, false);
yellow = this.color.bind(this, 33, false);
blue = this.color.bind(this, 34, false);
magenta = this.color.bind(this, 35, false);
cyan = this.color.bind(this, 36, false);
white = this.color.bind(this, 37, false);
bgBlack = this.color.bind(this, 40, true);
bgRed = this.color.bind(this, 41, true);
bgGreen = this.color.bind(this, 42, true);
bgYellow = this.color.bind(this, 43, true);
bgBlue = this.color.bind(this, 44, true);
bgMagenta = this.color.bind(this, 45, true);
bgCyan = this.color.bind(this, 46, true);
bgWhite = this.color.bind(this, 47, true);
})();

const color = colorize;
```

```ts title="typescript"
console.log(color.red("foo")); // 'foo' (red letters)
console.log(color.bgBlue("foo", "bar")); // 'foo bar' (blue background)
console.log(color.bgWhite(color.yellow("foo"), color.green("foo"))); // 'foo bar' (first
//word in yellow letters, second word in green letters, white background for both)

console.log(colorize.red("foo")); // 'foo' (red letters)
console.log(colorize.bgBlue("foo", "bar")); // 'foo bar' (blue background)
console.log(colorize.bgWhite(colorize.yellow("foo"), colorize.green("foo"))); // 'foo bar' (first
//word in yellow letters, second word in green letters, white background for both)
```
25 changes: 25 additions & 0 deletions i18n/zh/docusaurus-plugin-content-docs/current/compact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: compact [压缩]
tags: [array, beginner]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: 在 TypeScript、JavaScript 和 Deno 中实现 "compact" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

![TS](https://img.shields.io/badge/supports-typescript-blue.svg?style=flat-square)
![JS](https://img.shields.io/badge/supports-javascript-yellow.svg?style=flat-square)
![Deno](https://img.shields.io/badge/supports-deno-green.svg?style=flat-square)

从数组中移除假值。

使用 `Array.prototype.filter()` 来过滤掉假值 `(false、null、0、""、undefined 和 NaN)`

```ts title="typescript"
const compact = (arr: any[]) => arr.filter(Boolean);
```

```ts title="typescript"
compact([0, 1, false, 2, "", 3, "a", Number("e") * 23, NaN, "s", 34]); // [ 1, 2, 3, 'a', 's', 34 ]
```
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ tags: [browser, string, advanced]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: Implementation of "copyToClipboard" in typescript, javascript and deno.
description: 在 TypeScript、JavaScript 和 Deno 中实现 "copyToClipboard" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

2 changes: 1 addition & 1 deletion i18n/zh/docusaurus-plugin-content-docs/current/debounce.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ tags: [function, intermediate]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: Implementation of "debounce" in typescript, javascript and deno.
description: 在 TypeScript、JavaScript 和 Deno 中实现 "debounce" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

30 changes: 30 additions & 0 deletions i18n/zh/docusaurus-plugin-content-docs/current/defer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: defer [推迟]
tags: [function, intermediate]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: 在 TypeScript、JavaScript 和 Deno 中实现 "defer" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

![JS](https://img.shields.io/badge/supports-javascript-yellow.svg?style=flat-square)
![TODO](https://img.shields.io/badge///TODO-blue.svg?style=flat-square)

延迟调用一个函数,直到当前调用栈已经清空。

使用 `setTimeout()`,设置超时为 1 毫秒,向浏览器事件队列中添加一个新事件,以便让渲染引擎完成其工作。使用扩展运算符 (`...`) 来向函数提供任意数量的参数。

```js
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
```

```js
// Example A:
defer(console.log, "a"), console.log("b"); // logs 'b' then 'a'

// Example B:
document.querySelector("#someElement").innerHTML = "Hello";
longRunningFunction(); // Browser will not update the HTML until this has finished
defer(longRunningFunction); // Browser will update the HTML then run the function
```
51 changes: 51 additions & 0 deletions i18n/zh/docusaurus-plugin-content-docs/current/delay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: delay [延迟]
tags: [function, intermediate]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: 在 TypeScript、JavaScript 和 Deno 中实现 "delay" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

![TS](https://img.shields.io/badge/supports-typescript-blue.svg?style=flat-square)
![JS](https://img.shields.io/badge/supports-javascript-yellow.svg?style=flat-square)
![Deno](https://img.shields.io/badge/supports-deno-green.svg?style=flat-square)

`wait` 毫秒后调用提供的函数。

使用 `setTimeout()` 来延迟执行 fn。

使用扩展运算符 `(...)` 来向函数提供任意数量的参数。

```ts title="typescript"
const delay = (fn: Func, wait: number, ...args: any[]) =>
setTimeout(fn, wait, ...args);

// Return a promise, Resolve after `wait` milliseconds.
const delayedPromise = (wait: number = 300, ...args: any[]) =>
new Promise((resolve) => {
delay(resolve, wait, ...args);
});
```

```ts title="typescript"
delay(
function (text) {
console.log(text);
},
1000,
"later"
); // Logs 'later' after one second.

// delayedPromise
let counter = 0;
const updateState = () => {
counter++;
};
const debouncedUpdate = debounce(updateState);
debouncedUpdate(); // counter == 1
debouncedUpdate(); // counter == 1
await delayedPromise(); // counter == 1
assertEquals(counter, 1);
```
46 changes: 46 additions & 0 deletions i18n/zh/docusaurus-plugin-content-docs/current/ellipsis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: ellipsis [省略号]
tags: [string, beginner]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: 在 TypeScript、JavaScript 和 Deno 中实现 "ellipsis" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

![JS](https://img.shields.io/badge/supports-javascript-yellow.svg?style=flat-square)
![TODO](https://img.shields.io/badge///TODO-blue.svg?style=flat-square)

将字符串截断到指定长度。

判断字符串的 `length` 是否大于 num。

返回截断到所需长度的字符串,并在末尾添加 `'...'`,或者返回原始字符串。

```ts title="typescript"
const truncateString = (
str: string,
num: number = str.length,
ellipsisStr = "..."
) =>
str.length >= num
? str.slice(0, num >= ellipsisStr.length ? num - ellipsisStr.length : num) +
ellipsisStr
: str;

const ellipsis = (str: string, num: number = str.length, ellipsisStr = "...") =>
str.length >= num
? str.slice(0, num >= ellipsisStr.length ? num - ellipsisStr.length : num) +
ellipsisStr
: str;
```

```ts title="typescript"
truncateString("boomerang", 7); // 'boom...'

ellipsis("boomerang", 5, ".."); // "boo.."

ellipsis("boomerang"); // "boomer..."

ellipsis("boomerang", undefined, "♦♦♦"); // "boomer♦♦♦"
```
44 changes: 44 additions & 0 deletions i18n/zh/docusaurus-plugin-content-docs/current/equals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: equals [相等]
tags: [object, array, type, advanced]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: 在 TypeScript、JavaScript 和 Deno 中实现 "equals" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

![TS](https://img.shields.io/badge/supports-typescript-blue.svg?style=flat-square)
![JS](https://img.shields.io/badge/supports-javascript-yellow.svg?style=flat-square)
![Deno](https://img.shields.io/badge/supports-deno-green.svg?style=flat-square)

执行两个值之间的深度比较,以确定它们是否等价。

检查这两个值是否相同,如果它们都是具有相同时间的 `Date` 对象,可以使用 `Date.getTime()`,或者如果它们都是非对象值并且具有等价的值(使用严格比较)。

检查只有一个值是 null 或 undefined,或者它们的原型不同。如果上述条件都不满足,使用 `Object.keys()` 检查这两个值是否具有相同数量的键,然后使用 Array.`prototype.every()` 检查第一个值中的每个键是否存在于第二个值中,并且通过递归调用此方法来检查它们是否等价。

```ts title="typescript"
const equals = (a, b) => {
if (a === b) return true;
if (a instanceof Date && b instanceof Date)
return a.getTime() === b.getTime();
if (!a || !b || (typeof a !== "object" && typeof b !== "object"))
return a === b;
if (a.prototype !== b.prototype) return false;
let keys = Object.keys(a);
if (keys.length !== Object.keys(b).length) return false;
return keys.every((k) => equals(a[k], b[k]));
};
```

```ts title="typescript"
equals(
{ a: [2, { e: 3 }], b: [4], c: "foo" },
{ a: [2, { e: 3 }], b: [4], c: "foo" }
); // true
equals([1, 2, 3], { 0: 1, 1: 2, 2: 3 }); // true

// equals(1, "1");// compile error
deepEquals(1, "1"); //false// no compile error
```
2 changes: 1 addition & 1 deletion i18n/zh/docusaurus-plugin-content-docs/current/flatten.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ tags: [array, intermediate]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: Implementation of "flatten" in typescript, javascript and deno.
description: 在 TypeScript、JavaScript 和 Deno 中实现 "flatten" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ tags: [object, recursion, intermediate]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: Implementation of "flattenObject" in typescript, javascript and deno.
description: 在 TypeScript、JavaScript 和 Deno 中实现 "flattenObject" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

2 changes: 1 addition & 1 deletion i18n/zh/docusaurus-plugin-content-docs/current/groupBy.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ tags: [array, object, intermediate]
author_title: Deepak Vishwakarma
author_url: https://github.com/deepakshrma
author_image_url: https://avatars2.githubusercontent.com/u/7682731?s=400
description: Implementation of "groupBy" in typescript, javascript and deno.
description: 在 TypeScript、JavaScript 和 Deno 中实现 "groupBy" 的方法。
image: https://www.positronx.io/wp-content/uploads/2018/11/positronx-banner-1152-1.jpg
---

Loading

0 comments on commit 472ed5a

Please sign in to comment.