Skip to content

Commit

Permalink
op
Browse files Browse the repository at this point in the history
  • Loading branch information
PingHuskar committed Jan 17, 2025
1 parent 32b0ca0 commit 0b1a68e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
14 changes: 5 additions & 9 deletions function/TB.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const THAINUMBERWORDS = require("../const/array/THAINUMBERWORDS");
module.exports = (BT, error = `Invalid String`) => {
if (!BT) return undefined;

if (/$/.test(BT)) BT = `${BT}${FULLBAHT}`;
if (!/$/.test(BT) && !/$/.test(BT)) return error;
if (BT.endsWith(BAHT)) BT = `${BT}${FULLBAHT}`;
if (!BT.endsWith(SATANG) && !BT.endsWith(FULLBAHT)) return error;

const [moneyBaht, moneySatang] = BT.split(BAHT);

if (/$/.test(moneyBaht) && !moneySatang) {
if (moneyBaht.endsWith(SATANG) && !moneySatang) {
return `0.${SatangNum(moneyBaht.replace(SATANG, ``))}`;
}

Expand Down Expand Up @@ -57,11 +57,7 @@ module.exports = (BT, error = `Invalid String`) => {

const VL =
SatangNum(
million
.replace(/.+/, ``)
.replace(/.+/, ``)
.replace(/.+/, ``)
.replace(/.+/, ``)
million.replace(/.+(|||)/, ``)
) || `00`;

moneyBahts.push(
Expand All @@ -72,7 +68,7 @@ module.exports = (BT, error = `Invalid String`) => {
);
}

return `${removeLeadingingZeros(moneyBahts.reverse().join(""))}.${SatangNum(
return `${removeLeadingingZeros(moneyBahts.toReversed().join(""))}.${SatangNum(
moneySatang.replace(SATANG, ``)
)}`;
};
15 changes: 4 additions & 11 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ test(`PrintSatangs 2d+`, () => {
test(`BulkBahtText`, () =>{
expect(BulkBahtText(`อย่าลืมใช้โค้ด 9arm นะครับ ใช้เถอะ เค้าจะได้จ้างผมต่อ`)).toBe(`อย่าลืมใช้โค้ด 9arm นะครับ ใช้เถอะ เค้าจะได้จ้างผมต่อ`)
expect(
BulkBahtText(`30฿รักษาทุกโรค`, /(\d+)(\.\d{0,2}0*)?\฿/g).replace(
BulkBahtText(`30฿รักษาทุกโรค`, /(\d+)(\.\d{0,2}0*)?฿/g).replace(
FULLBAHT,
``
)
).toBe(`สามสิบบาทรักษาทุกโรค`);
expect(
BulkBahtText(`เงินดิจิมอน 10000฿ ใช้ยังไง ได้วันไหน ใครได้บ้าง`)
.replace(FULLBAHT, ``)
.replace(RegExp(`฿`,`g`), ``)
.replace(/฿/g, ``)
).toBe(`เงินดิจิมอน หนึ่งหมื่นบาท ใช้ยังไง ได้วันไหน ใครได้บ้าง`);
expect(BulkBahtText(`"900 ถูกมาก" ตุยไปละ`).replace(FULLBAHT, ``)).toBe(
`"เก้าร้อยบาท ถูกมาก" ตุยไปละ`
Expand Down Expand Up @@ -389,8 +389,8 @@ test('Reverse BahtText', () => {
});

test('repeat',() => {
expect(repeat(`ค`,[3])).toBe(`คคค`);
expect(`ปิดสวิตซ์ ${repeat(`ป`, [3])} ป่าหี่`).toBe(
expect(repeat('ค',[3])).toBe(`คคค`);
expect(`ปิดสวิตซ์ ${repeat('ป', [3])} ป่าหี่`).toBe(
`ปิดสวิตซ์ ปปป ป่าหี่`
);
})
Expand Down Expand Up @@ -451,13 +451,6 @@ test(`IsValidText`, () => {
expect(IsValidText(`สองสิบ`)).toBe(false);
});

test(`Bool Test`, () => {
expect(true).toBe(true)
expect(true).toBe(!false)
expect(false).toBe(false);
expect(false).toBe(!true)
})

test(`IsValidTB`, () => {
expect(IsValidTB(`แปดสิบแปดบาท`)).toBe(true);
});
Expand Down
6 changes: 3 additions & 3 deletions octal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ test(`isOctal`, () => {
expect(isOctal(`0o77_`)).toBe(false);
expect(isOctal(`0o_77_`)).toBe(false);
expect(isOctal(`0o7__7`)).toBe(false);
expect(isOctal(`0000877`)).toBe(!true);
expect(isOctal(`000o77`)).toBe(!true);
expect(isOctal(`000oo77`)).toBe(!true);
expect(isOctal(`0000877`)).toBe(false);
expect(isOctal(`000o77`)).toBe(false);
expect(isOctal(`000oo77`)).toBe(false);
expect(isOctal(`053256462753462`)).toBe(true);
expect(isOctal(0o77)).toBe(undefined);
expect(isOctal(123)).toBe(undefined);
Expand Down
6 changes: 2 additions & 4 deletions performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const performance = async (money_array) => {
console.time("thai-baht-text");

for (const money of money_array) {
// console.log(THBText(money));
await pass(THBText(money));
pass(THBText(money));
}

console.timeEnd("thai-baht-text");
Expand All @@ -20,8 +19,7 @@ const performanceBR = async (money_array) => {
console.time("BahtRext");

for (const money of money_array) {
// console.log(BahtRext.BF(money));
await pass(BahtRext.BF(money));
pass(BahtRext.BF(money));
}

console.timeEnd("BahtRext");
Expand Down

0 comments on commit 0b1a68e

Please sign in to comment.