mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
Make ArbitraryBase Unicode-aware (#1299)
* Make ArbitraryBase Unicode-aware https://mathiasbynens.be/notes/javascript-unicode#counting-symbols * Fix performance bug and add Unicode test * Add BigInt version and push output chars to array
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { convertArbitraryBase } from '../ArbitraryBase'
|
||||
import { convertArbitraryBase, convertArbitraryBaseBigIntVersion } from '../ArbitraryBase'
|
||||
|
||||
test('Check the answer of convertArbitraryBase(98, 0123456789, 01234567) is 142', () => {
|
||||
const res = convertArbitraryBase('98', '0123456789', '01234567')
|
||||
@@ -34,3 +34,23 @@ test('Check the answer of convertArbitraryBase(111, 0123456789, abcdefgh) is bfh
|
||||
const res = convertArbitraryBase('111', '0123456789', 'abcdefgh')
|
||||
expect(res).toBe('bfh')
|
||||
})
|
||||
|
||||
test('Unicode awareness', () => {
|
||||
const res = convertArbitraryBase('98', '0123456789', '💝🎸🦄')
|
||||
expect(res).toBe('🎸💝🎸🦄🦄')
|
||||
})
|
||||
|
||||
test('zero', () => {
|
||||
const res = convertArbitraryBase('0', '0123456789', 'abc')
|
||||
expect(res).toBe('a')
|
||||
})
|
||||
|
||||
test('BigInt version with input string of arbitrary length', () => {
|
||||
const resBigIntVersion = convertArbitraryBaseBigIntVersion(
|
||||
String(10n ** 100n),
|
||||
'0123456789',
|
||||
'0123456789abcdefghijklmnopqrstuvwxyz'
|
||||
)
|
||||
|
||||
expect(resBigIntVersion).toBe((10n ** 100n).toString(36))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user