vanillaaont
Version:
simple all-or-nothing transform in nothing but vanilla js
43 lines (36 loc) • 1.18 kB
JavaScript
;
{
const { T, TU } = require('./index.js');
const atob = require('atob');
const btoa = require('btoa');
// oh sorry, did I say vanilla? I meant vanilla with sprinkles. There you go.
// or how about some vanilla Choc Chip?
const x = 'a-0--bcdefghjijklmnopqrstuvwxyzabcdefghjijklmnopqrstuvwxyzabcdefghjijklmnopqrstuvwxyzabcdefghjijklmnopqrstuvwxyz';
test();
function test_change(i,tot) {
const a = btoa(x);
const tb = T(a);
let tbp = tb.split('');
tbp[i] = 'A';
tbp = tbp.join('');
const utb = TU(tbp);
console.log(tb);
console.log(tbp);
console.log(utb);
console.log(a);
console.log(x);
console.log(atob(utb));
tot.val += score(x,atob(utb));
tot.count += 1;
}
function test() {
const total = { val: 0, count: 0 };
btoa(x).split('').forEach((c,i) => c !== '=' ? test_change(i,total) : 0);
console.log(`Total displacements: ${total.val}, average: ${total.val/total.count}, % of input length: ${(total.val/total.count)/x.length*100}` );
}
function score(a,b) {
let dif = 0;
Array.from(a).forEach( (c,i) => { dif = dif + (c == b[i] ? 0 : 1) } );
return dif;
}
}