Last active
June 4, 2020 18:51
-
-
Save iwestlin/906bc7da33b395657a592fbb2dffbdd9 to your computer and use it in GitHub Desktop.
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
function gen_arr_from (start, length) { | |
return Array(length).fill(start).map((v, i) => v + i).map(v => String.fromCodePoint(v)) | |
} | |
const zeros = [0x24FF, 0x3007, 0x1F10B, 0x1F10C, 0x07C0, 0x104A0, 0x11136, 0x1C50, 0x1810, 0x0ED0, 0x1040, 0x17E0, 0x1946, 0x1BB0, 0xFF10, 0x19D0, 0x0D66, 0x0AE6, 0x1C40, 0x1A90, 0x1A80, 0x0CE6, 0x0C66, 0x09E6, 0x0A66, 0x0B66, 0x0BE6].map(v => String.fromCodePoint(v)) | |
const zero_to_nines = [ | |
gen_arr_from(0x1D7CE, 10), | |
gen_arr_from(0x1D7D8, 10), | |
gen_arr_from(0x1D7E2, 10), | |
gen_arr_from(0x1D7EC, 10), | |
gen_arr_from(0x1D7F6, 10) | |
] | |
const one_to_nines = [ | |
gen_arr_from(0x2776, 9), | |
gen_arr_from(0x2780, 9), | |
gen_arr_from(0x278A, 9), | |
gen_arr_from(0x2460, 9), | |
gen_arr_from(0x2474, 9), | |
gen_arr_from(0x24F5, 9) | |
] | |
module.exports = function transfrom (num_str) { // num_str must be the combination of 0123456789 | |
const input_numbers = String(num_str).trim().split('').map(v => Number(v)) | |
const dicts = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
if (input_numbers.some(v => !dicts.includes(v))) throw new Error('invalid input: ' + num_str) | |
const random_zero = zeros[~~(Math.random() * zeros.length)] | |
const all_set = zero_to_nines.concat(one_to_nines.map(arr => [random_zero].concat(arr))) | |
return input_numbers.map(v => { | |
const random_set = all_set[~~(Math.random() * all_set.length)] | |
return random_set[v] | |
}).join('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment