From 9f725624e9182b1553363c9b44feb2b7d6da80de Mon Sep 17 00:00:00 2001 From: albilaga Date: Mon, 3 Oct 2022 21:59:29 +0700 Subject: [PATCH 01/16] Add md5 raw --- csharp/Pehape/String/Md5.cs | 23 +++++++++++++++ csharp/Tests/String/Md5Tests.cs | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 csharp/Pehape/String/Md5.cs create mode 100644 csharp/Tests/String/Md5Tests.cs diff --git a/csharp/Pehape/String/Md5.cs b/csharp/Pehape/String/Md5.cs new file mode 100644 index 0000000..fe9bc07 --- /dev/null +++ b/csharp/Pehape/String/Md5.cs @@ -0,0 +1,23 @@ +using System.Globalization; +using System.Text; + +namespace Pehape { + public static partial class PHP { + public static byte[] Md5Raw(string input) { + using var md5 = System.Security.Cryptography.MD5.Create(); + var inputBytes = Encoding.ASCII.GetBytes(input); + var hashBytes = md5.ComputeHash(inputBytes); + return hashBytes; + } + + public static string Md5(string input) { + var hashBytes = Md5Raw(input); + var sb = new StringBuilder(); + foreach (var t in hashBytes) { + sb.Append(t.ToString("X2", CultureInfo.InvariantCulture).ToLowerInvariant()); + } + + return sb.ToString(); + } + } +} \ No newline at end of file diff --git a/csharp/Tests/String/Md5Tests.cs b/csharp/Tests/String/Md5Tests.cs new file mode 100644 index 0000000..b1b2dc5 --- /dev/null +++ b/csharp/Tests/String/Md5Tests.cs @@ -0,0 +1,51 @@ +using System.Globalization; +using System.Text; +using FluentAssertions; +using Pehape; +using Xunit; + +namespace Tests.String { + public class Md5Tests { + //test cases from https://github.com/php/php-src/blob/master/ext/standard/tests/strings/md5.phpt + [InlineData("", "d41d8cd98f00b204e9800998ecf8427e")] + [InlineData("a", "0cc175b9c0f1b6a831c399e269772661")] + [InlineData("abc", "900150983cd24fb0d6963f7d28e17f72")] + [InlineData("message digest", "f96b697d7cb7938d525a2f31aaf161d0")] + [InlineData("abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b")] + [InlineData("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "d174ab98d277d9f5a5611c2c9f419d9f")] + [InlineData("12345678901234567890123456789012345678901234567890123456789012345678901234567890", + "57edf4a22be3c955ac49da2e2107b67a")] + + //test cases from https://github.com/php/php-src/blob/master/ext/standard/tests/strings/md5_basic1.phpt + [InlineData("apple", "1f3870be274f6c49b3e31a0c6728957f")] + [Theory] + public void ReturnCorrectResult(string input, string result) { + PHP.Md5(input).Should().Be(result); + } + + //test cases from https://github.com/php/php-src/blob/master/ext/standard/tests/strings/md5.phpt + [InlineData("", "d41d8cd98f00b204e9800998ecf8427e")] + [InlineData("a", "0cc175b9c0f1b6a831c399e269772661")] + [InlineData("abc", "900150983cd24fb0d6963f7d28e17f72")] + [InlineData("message digest", "f96b697d7cb7938d525a2f31aaf161d0")] + [InlineData("abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b")] + [InlineData("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "d174ab98d277d9f5a5611c2c9f419d9f")] + [InlineData("12345678901234567890123456789012345678901234567890123456789012345678901234567890", + "57edf4a22be3c955ac49da2e2107b67a")] + + //test cases from https://github.com/php/php-src/blob/master/ext/standard/tests/strings/md5_basic1.phpt + [InlineData("apple", "1f3870be274f6c49b3e31a0c6728957f")] + [Theory] + public void ReturnRawCorrectResult(string input, string result) { + var raw = PHP.Md5Raw(input); + var sb = new StringBuilder(); + foreach (var t in raw) { + sb.Append(t.ToString("X2", CultureInfo.InvariantCulture).ToLowerInvariant()); + } + + sb.ToString().Should().Be(result); + } + } +} \ No newline at end of file From 1b11630b7ad78b148bc6c40bdf4cc2c785cb1a28 Mon Sep 17 00:00:00 2001 From: albilaga Date: Mon, 3 Oct 2022 22:04:22 +0700 Subject: [PATCH 02/16] Add Doc --- csharp/Pehape/String/Md5.cs | 10 ++++++++++ csharp/Tests/String/Md5Tests.cs | 1 + 2 files changed, 11 insertions(+) diff --git a/csharp/Pehape/String/Md5.cs b/csharp/Pehape/String/Md5.cs index fe9bc07..da82bf4 100644 --- a/csharp/Pehape/String/Md5.cs +++ b/csharp/Pehape/String/Md5.cs @@ -3,6 +3,11 @@ namespace Pehape { public static partial class PHP { + /// + /// The Md5Raw function calculates the md5 hash of a string + /// + /// String to be calculated + /// 16 character binary format public static byte[] Md5Raw(string input) { using var md5 = System.Security.Cryptography.MD5.Create(); var inputBytes = Encoding.ASCII.GetBytes(input); @@ -10,6 +15,11 @@ public static byte[] Md5Raw(string input) { return hashBytes; } + /// + /// The Md5 function calculates the md5 hash of a string + /// + /// String to be calculated + /// 32 character hex number public static string Md5(string input) { var hashBytes = Md5Raw(input); var sb = new StringBuilder(); diff --git a/csharp/Tests/String/Md5Tests.cs b/csharp/Tests/String/Md5Tests.cs index b1b2dc5..827a1fa 100644 --- a/csharp/Tests/String/Md5Tests.cs +++ b/csharp/Tests/String/Md5Tests.cs @@ -45,6 +45,7 @@ public void ReturnRawCorrectResult(string input, string result) { sb.Append(t.ToString("X2", CultureInfo.InvariantCulture).ToLowerInvariant()); } + raw.Length.Should().Be(16); sb.ToString().Should().Be(result); } } From c6d455567ef0b0ff5f592e6489670a82f34bf4bb Mon Sep 17 00:00:00 2001 From: albilaga Date: Mon, 3 Oct 2022 22:07:43 +0700 Subject: [PATCH 03/16] fix tests --- csharp/Pehape/String/Md5.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/Pehape/String/Md5.cs b/csharp/Pehape/String/Md5.cs index da82bf4..f2a9126 100644 --- a/csharp/Pehape/String/Md5.cs +++ b/csharp/Pehape/String/Md5.cs @@ -24,7 +24,7 @@ public static string Md5(string input) { var hashBytes = Md5Raw(input); var sb = new StringBuilder(); foreach (var t in hashBytes) { - sb.Append(t.ToString("X2", CultureInfo.InvariantCulture).ToLowerInvariant()); + sb.Append(t.ToString("x2", CultureInfo.InvariantCulture)); } return sb.ToString(); From b0b600c93442289bdf320054800531f271e5bfbb Mon Sep 17 00:00:00 2001 From: dkelxldk Date: Fri, 7 Oct 2022 09:49:08 +0700 Subject: [PATCH 04/16] feat(typescript-lcfirst): lowercase the first characters of the text --- typescript/src/string/index.ts | 3 ++- typescript/src/string/lcfirst.test.ts | 17 +++++++++++++++++ typescript/src/string/lcfirst.ts | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 typescript/src/string/lcfirst.test.ts create mode 100644 typescript/src/string/lcfirst.ts diff --git a/typescript/src/string/index.ts b/typescript/src/string/index.ts index feb449b..332944a 100644 --- a/typescript/src/string/index.ts +++ b/typescript/src/string/index.ts @@ -1,2 +1,3 @@ export * from "./explode"; -export * from "./implode"; \ No newline at end of file +export * from "./implode"; +export * from "./lcfirst"; \ No newline at end of file diff --git a/typescript/src/string/lcfirst.test.ts b/typescript/src/string/lcfirst.test.ts new file mode 100644 index 0000000..bb522a0 --- /dev/null +++ b/typescript/src/string/lcfirst.test.ts @@ -0,0 +1,17 @@ +import { lcfirst } from "./lcfirst"; + +const text = "Shizumu you ni tokete yuku you ni."; + +describe("valid parameters", () => { + it("should return lowercased first characters from capital text", () => { + expect(lcfirst(text)).toEqual("shizumu you ni tokete yuku you ni."); + }); + + it("should return lowercased first characters from all uppercased text", () => { + expect(lcfirst(text.toUpperCase())).toEqual("sHIZUMU YOU NI TOKETE YUKU YOU NI."); + }); + + it("should return lowercased first characters from all lowercased text", () => { + expect(lcfirst(text.toLowerCase())).toEqual("shizumu you ni tokete yuku you ni."); + }); +}); \ No newline at end of file diff --git a/typescript/src/string/lcfirst.ts b/typescript/src/string/lcfirst.ts new file mode 100644 index 0000000..0294c00 --- /dev/null +++ b/typescript/src/string/lcfirst.ts @@ -0,0 +1 @@ +export const lcfirst = (text: string): string => text.charAt(0).toLowerCase() + text.slice(1); \ No newline at end of file From 295b08812b93349f40d53bd6a9b7d16c3d644548 Mon Sep 17 00:00:00 2001 From: dkelxldk Date: Sat, 8 Oct 2022 12:43:35 +0700 Subject: [PATCH 05/16] docs(typescript-lcfirst): add JSDoc --- typescript/src/string/lcfirst.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/typescript/src/string/lcfirst.ts b/typescript/src/string/lcfirst.ts index 0294c00..cc7e512 100644 --- a/typescript/src/string/lcfirst.ts +++ b/typescript/src/string/lcfirst.ts @@ -1 +1,6 @@ +/** + * Make a string's first character lowercase. + * @param {String} text The input text. + * @returns {String} a string with the first character of string lowercased. + */ export const lcfirst = (text: string): string => text.charAt(0).toLowerCase() + text.slice(1); \ No newline at end of file From 6cdf8f30960242c41d2cfd0adcd4937bce29cc1e Mon Sep 17 00:00:00 2001 From: dkelxldk Date: Sat, 8 Oct 2022 12:43:58 +0700 Subject: [PATCH 06/16] test(typescript-lcfirst): add more test case --- typescript/src/string/lcfirst.test.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/typescript/src/string/lcfirst.test.ts b/typescript/src/string/lcfirst.test.ts index bb522a0..86b6bab 100644 --- a/typescript/src/string/lcfirst.test.ts +++ b/typescript/src/string/lcfirst.test.ts @@ -2,7 +2,19 @@ import { lcfirst } from "./lcfirst"; const text = "Shizumu you ni tokete yuku you ni."; -describe("valid parameters", () => { +describe("parameter is empty string", () => { + it("should return empty string", () => { + expect(lcfirst("")).toBe(""); + }); +}); + +describe("parameter is whitespace", () => { + it("should return the whitespace", () => { + expect(lcfirst(" ")).toBe(" "); + }); +}); + +describe("parameter not empty string", () => { it("should return lowercased first characters from capital text", () => { expect(lcfirst(text)).toEqual("shizumu you ni tokete yuku you ni."); }); @@ -14,4 +26,17 @@ describe("valid parameters", () => { it("should return lowercased first characters from all lowercased text", () => { expect(lcfirst(text.toLowerCase())).toEqual("shizumu you ni tokete yuku you ni."); }); + + it("should return the same for non alphabetical characters", () => { + expect(lcfirst("沈むように溶けてゆくように")).toEqual("沈むように溶けてゆくように"); + }); + + it("should return lowercased first characters from alphabetical with special characters", () => { + expect(lcfirst("Éxample")).toEqual("éxample"); + }); + + it("should return the same as input", () => { + expect(lcfirst("123456789")).toBe("123456789"); + expect(lcfirst("!@#$%%")).toBe("!@#$%%"); + }); }); \ No newline at end of file From 951c3b67cf9b4569a29a68c12c82ea64b2b80c9e Mon Sep 17 00:00:00 2001 From: Fikri Date: Sun, 9 Oct 2022 12:47:15 +0700 Subject: [PATCH 07/16] feat(typescript): str_split --- typescript/src/string/index.ts | 1 + typescript/src/string/str_split.test.ts | 25 +++++++++++++++++++++ typescript/src/string/str_split.ts | 30 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 typescript/src/string/str_split.test.ts create mode 100644 typescript/src/string/str_split.ts diff --git a/typescript/src/string/index.ts b/typescript/src/string/index.ts index 3111a95..6dc28ef 100644 --- a/typescript/src/string/index.ts +++ b/typescript/src/string/index.ts @@ -2,3 +2,4 @@ export * from "./explode"; export * from "./implode"; export * from "./str_repeat"; export * from "./chr"; +export * from "./str_split"; \ No newline at end of file diff --git a/typescript/src/string/str_split.test.ts b/typescript/src/string/str_split.test.ts new file mode 100644 index 0000000..6ffc735 --- /dev/null +++ b/typescript/src/string/str_split.test.ts @@ -0,0 +1,25 @@ +import { str_split } from "./str_split"; + +const str = "Hello World!"; + +describe("string split", () => { + it("should be able to return every letter as element of the array", () => { + expect(str_split(str)).toEqual( + ["H", "e", "l", "l", "o", " ", "W", "o", "r", "l", "d", "!"] + ); + }); + + it("should be able to return 2 or more letter as element of the array depend on number of len", () => { + expect(str_split(str, 2)).toEqual(["He", "ll", "o ", "Wo", "rl", "d!"]); + expect(str_split(str, 3)).toEqual(["Hel", "lo ", "Wor", "ld!"]); + expect(str_split(str, 4)).toEqual(["Hell", "o Wo", "rld!"]); + }); + + it("should be able to return false", () => { + expect(str_split(str, -1)).toEqual(false); + }); + + it("should be able to return the entire string as the only element of the array", () => { + expect(str_split(str, 15)).toEqual(["Hello World!"]); + }); +}); diff --git a/typescript/src/string/str_split.ts b/typescript/src/string/str_split.ts new file mode 100644 index 0000000..9e9ee5f --- /dev/null +++ b/typescript/src/string/str_split.ts @@ -0,0 +1,30 @@ +/** + * str_split — Convert a string to an array + * @param str - The string to be convert. + * @param len - Maximum length of the chunk. + * @returns If the optional length parameter is specified, the returned array will be broken down into chunks with each being length in length, except the final chunk which may be shorter if the string does not divide evenly. The default length is 1, meaning every chunk will be one byte in size. + */ +export const str_split = (str: string, len?: number): string[] | false => { + if (typeof len !== "undefined" && typeof len === "number") { + if (len < 0) return false; + + const arr: string[] = []; + let result = ""; + let counter = 0; + for (let i=0; i Date: Mon, 10 Oct 2022 13:47:14 +0700 Subject: [PATCH 08/16] add: handler for str param --- typescript/src/string/str_split.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/typescript/src/string/str_split.ts b/typescript/src/string/str_split.ts index 9e9ee5f..f41240c 100644 --- a/typescript/src/string/str_split.ts +++ b/typescript/src/string/str_split.ts @@ -5,6 +5,7 @@ * @returns If the optional length parameter is specified, the returned array will be broken down into chunks with each being length in length, except the final chunk which may be shorter if the string does not divide evenly. The default length is 1, meaning every chunk will be one byte in size. */ export const str_split = (str: string, len?: number): string[] | false => { + if (typeof str === "undefined" || typeof str !== "string") return false; if (typeof len !== "undefined" && typeof len === "number") { if (len < 0) return false; From f729ad9ab9a0db8aa336d5f39f12d6bd80c34a28 Mon Sep 17 00:00:00 2001 From: Fikri Date: Tue, 11 Oct 2022 19:39:59 +0700 Subject: [PATCH 09/16] refactor: redudansi pengecekan --- typescript/src/string/str_split.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/typescript/src/string/str_split.ts b/typescript/src/string/str_split.ts index f41240c..b0f8eaa 100644 --- a/typescript/src/string/str_split.ts +++ b/typescript/src/string/str_split.ts @@ -1,12 +1,12 @@ /** * str_split — Convert a string to an array - * @param str - The string to be convert. + * @param str - The input string. * @param len - Maximum length of the chunk. * @returns If the optional length parameter is specified, the returned array will be broken down into chunks with each being length in length, except the final chunk which may be shorter if the string does not divide evenly. The default length is 1, meaning every chunk will be one byte in size. */ -export const str_split = (str: string, len?: number): string[] | false => { - if (typeof str === "undefined" || typeof str !== "string") return false; - if (typeof len !== "undefined" && typeof len === "number") { +export const str_split = (str: string, len = 1): string[] | false => { + if (typeof str !== "string") return false; + if (typeof len === "number") { if (len < 0) return false; const arr: string[] = []; @@ -26,6 +26,6 @@ export const str_split = (str: string, len?: number): string[] | false => { return arr; } - return str.split(""); + return false; }; \ No newline at end of file From 519e3821b8b3abecc34cd5f12e0a266b1f1217ce Mon Sep 17 00:00:00 2001 From: Fikri Date: Sun, 9 Oct 2022 12:47:15 +0700 Subject: [PATCH 10/16] feat(typescript): str_split --- typescript/src/string/index.ts | 1 + typescript/src/string/str_split.test.ts | 25 +++++++++++++++++++++ typescript/src/string/str_split.ts | 30 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 typescript/src/string/str_split.test.ts create mode 100644 typescript/src/string/str_split.ts diff --git a/typescript/src/string/index.ts b/typescript/src/string/index.ts index 4ffc3bd..dd72cdc 100644 --- a/typescript/src/string/index.ts +++ b/typescript/src/string/index.ts @@ -3,3 +3,4 @@ export * from "./implode"; export * from "./lcfirst"; export * from "./str_repeat"; export * from "./chr"; +export * from "./str_split"; \ No newline at end of file diff --git a/typescript/src/string/str_split.test.ts b/typescript/src/string/str_split.test.ts new file mode 100644 index 0000000..6ffc735 --- /dev/null +++ b/typescript/src/string/str_split.test.ts @@ -0,0 +1,25 @@ +import { str_split } from "./str_split"; + +const str = "Hello World!"; + +describe("string split", () => { + it("should be able to return every letter as element of the array", () => { + expect(str_split(str)).toEqual( + ["H", "e", "l", "l", "o", " ", "W", "o", "r", "l", "d", "!"] + ); + }); + + it("should be able to return 2 or more letter as element of the array depend on number of len", () => { + expect(str_split(str, 2)).toEqual(["He", "ll", "o ", "Wo", "rl", "d!"]); + expect(str_split(str, 3)).toEqual(["Hel", "lo ", "Wor", "ld!"]); + expect(str_split(str, 4)).toEqual(["Hell", "o Wo", "rld!"]); + }); + + it("should be able to return false", () => { + expect(str_split(str, -1)).toEqual(false); + }); + + it("should be able to return the entire string as the only element of the array", () => { + expect(str_split(str, 15)).toEqual(["Hello World!"]); + }); +}); diff --git a/typescript/src/string/str_split.ts b/typescript/src/string/str_split.ts new file mode 100644 index 0000000..9e9ee5f --- /dev/null +++ b/typescript/src/string/str_split.ts @@ -0,0 +1,30 @@ +/** + * str_split — Convert a string to an array + * @param str - The string to be convert. + * @param len - Maximum length of the chunk. + * @returns If the optional length parameter is specified, the returned array will be broken down into chunks with each being length in length, except the final chunk which may be shorter if the string does not divide evenly. The default length is 1, meaning every chunk will be one byte in size. + */ +export const str_split = (str: string, len?: number): string[] | false => { + if (typeof len !== "undefined" && typeof len === "number") { + if (len < 0) return false; + + const arr: string[] = []; + let result = ""; + let counter = 0; + for (let i=0; i Date: Mon, 10 Oct 2022 13:47:14 +0700 Subject: [PATCH 11/16] add: handler for str param --- typescript/src/string/str_split.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/typescript/src/string/str_split.ts b/typescript/src/string/str_split.ts index 9e9ee5f..f41240c 100644 --- a/typescript/src/string/str_split.ts +++ b/typescript/src/string/str_split.ts @@ -5,6 +5,7 @@ * @returns If the optional length parameter is specified, the returned array will be broken down into chunks with each being length in length, except the final chunk which may be shorter if the string does not divide evenly. The default length is 1, meaning every chunk will be one byte in size. */ export const str_split = (str: string, len?: number): string[] | false => { + if (typeof str === "undefined" || typeof str !== "string") return false; if (typeof len !== "undefined" && typeof len === "number") { if (len < 0) return false; From 81a9643603fe6fd4b76f6ba0dde3d88cf397b559 Mon Sep 17 00:00:00 2001 From: Fikri Date: Tue, 11 Oct 2022 19:39:59 +0700 Subject: [PATCH 12/16] refactor: redudansi pengecekan --- typescript/src/string/str_split.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/typescript/src/string/str_split.ts b/typescript/src/string/str_split.ts index f41240c..b0f8eaa 100644 --- a/typescript/src/string/str_split.ts +++ b/typescript/src/string/str_split.ts @@ -1,12 +1,12 @@ /** * str_split — Convert a string to an array - * @param str - The string to be convert. + * @param str - The input string. * @param len - Maximum length of the chunk. * @returns If the optional length parameter is specified, the returned array will be broken down into chunks with each being length in length, except the final chunk which may be shorter if the string does not divide evenly. The default length is 1, meaning every chunk will be one byte in size. */ -export const str_split = (str: string, len?: number): string[] | false => { - if (typeof str === "undefined" || typeof str !== "string") return false; - if (typeof len !== "undefined" && typeof len === "number") { +export const str_split = (str: string, len = 1): string[] | false => { + if (typeof str !== "string") return false; + if (typeof len === "number") { if (len < 0) return false; const arr: string[] = []; @@ -26,6 +26,6 @@ export const str_split = (str: string, len?: number): string[] | false => { return arr; } - return str.split(""); + return false; }; \ No newline at end of file From 9c9dbb6934893753e26f0b626191867e5c21a604 Mon Sep 17 00:00:00 2001 From: Fikri Date: Mon, 17 Oct 2022 11:00:59 +0700 Subject: [PATCH 13/16] add test for zero input --- typescript/src/string/str_split.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/typescript/src/string/str_split.test.ts b/typescript/src/string/str_split.test.ts index 6ffc735..b90112d 100644 --- a/typescript/src/string/str_split.test.ts +++ b/typescript/src/string/str_split.test.ts @@ -16,6 +16,7 @@ describe("string split", () => { }); it("should be able to return false", () => { + expect(str_split(str, 0)).toEqual(false); expect(str_split(str, -1)).toEqual(false); }); From 35b288deca561fbced33326b6538c139752acff4 Mon Sep 17 00:00:00 2001 From: Fikri Date: Mon, 17 Oct 2022 11:01:19 +0700 Subject: [PATCH 14/16] early return --- typescript/src/string/str_split.ts | 31 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/typescript/src/string/str_split.ts b/typescript/src/string/str_split.ts index b0f8eaa..05e3548 100644 --- a/typescript/src/string/str_split.ts +++ b/typescript/src/string/str_split.ts @@ -6,26 +6,23 @@ */ export const str_split = (str: string, len = 1): string[] | false => { if (typeof str !== "string") return false; - if (typeof len === "number") { - if (len < 0) return false; + if (typeof len !== "number") return false; + if (len <= 0) return false; - const arr: string[] = []; - let result = ""; - let counter = 0; - for (let i=0; i Date: Mon, 17 Oct 2022 12:36:18 +0700 Subject: [PATCH 15/16] add some test --- typescript/src/string/str_split.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/typescript/src/string/str_split.test.ts b/typescript/src/string/str_split.test.ts index b90112d..f5e3da6 100644 --- a/typescript/src/string/str_split.test.ts +++ b/typescript/src/string/str_split.test.ts @@ -18,6 +18,10 @@ describe("string split", () => { it("should be able to return false", () => { expect(str_split(str, 0)).toEqual(false); expect(str_split(str, -1)).toEqual(false); + // @ts-expect-error + expect(str_split(str, "nol")).toEqual(false); + // @ts-expect-error + expect(str_split(1234567890, 3)).toEqual(false); }); it("should be able to return the entire string as the only element of the array", () => { From aa053a6576f3a168332880fa3e6e8aecd8e3bac9 Mon Sep 17 00:00:00 2001 From: Fikri Date: Mon, 17 Oct 2022 12:53:10 +0700 Subject: [PATCH 16/16] add message on @ts-expect-error --- typescript/src/string/str_split.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typescript/src/string/str_split.test.ts b/typescript/src/string/str_split.test.ts index f5e3da6..65bcea1 100644 --- a/typescript/src/string/str_split.test.ts +++ b/typescript/src/string/str_split.test.ts @@ -18,9 +18,9 @@ describe("string split", () => { it("should be able to return false", () => { expect(str_split(str, 0)).toEqual(false); expect(str_split(str, -1)).toEqual(false); - // @ts-expect-error + // @ts-expect-error because the second input is error in typescript expect(str_split(str, "nol")).toEqual(false); - // @ts-expect-error + // @ts-expect-error because the first input is error in typescript expect(str_split(1234567890, 3)).toEqual(false); });