-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ ✨ ag=>generator;新增string.ts和string.global.ts; collection 新增 iter_f…
…irst_not_null
- Loading branch information
Showing
10 changed files
with
107 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import assert from "node:assert"; | ||
import { iter_first_not_null } from "./collections.ts"; | ||
|
||
Deno.test("iter_first_not_null", () => { | ||
const result = iter_first_not_null([1, 2, 3, 4], (v) => { | ||
if (v > 2) { | ||
return `data:${v}`; | ||
} | ||
}); | ||
assert.equal(result, "data:3"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import "./ag.global.ts"; | ||
import "./generator.global.ts"; | ||
import "./collections.global.ts"; | ||
import "./encoding.global.ts"; | ||
import "./object.global.ts"; | ||
import "./readable_stream.global.ts"; | ||
import "./string.global.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { curryThisFn, extendsMethod } from "./func.ts"; | ||
import { str_reverse } from "./string.ts"; | ||
|
||
const reverse = curryThisFn(str_reverse); | ||
extendsMethod(String.prototype, "reverse", reverse); | ||
|
||
declare global { | ||
interface String { | ||
reverse(): string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* 反转字符串 | ||
*/ | ||
export const str_reverse = (str: string): string => { | ||
let restr = ""; | ||
/// 不能用 i++ < length 迭代,会有Unicode字符问题 | ||
for (const char of str) { | ||
restr = char + restr; | ||
} | ||
return restr; | ||
}; |