JSFiddle - React, Tailwind, and code Playground
by seong gyun jeon
JavaScript
function getComplement(x, r){
if (!x || !r) return [];
if (typeof x !== 'string') return [];
x = (x).toString(r);
var n = x.length;
return [
(Math.pow(r, n) - 1 - parseInt(x, r)).toString(r),
(Math.pow(r, n) - parseInt(x, r)).toString(r)
];
}
console.log(parseInt(getComplement('11', 10)[0], 10));
console.log(parseInt(getComplement('11', 10)[1], 10));
console.log(parseInt(getComplement('00101100', 2)[0], 2));
console.log(parseInt(getComplement('00101100', 2)[1], 2));