Skip to content

Instantly share code, notes, and snippets.

View e-mihaylin's full-sized avatar
🏠
Working from home

Eugene Mihaylin e-mihaylin

🏠
Working from home
View GitHub Profile
function SumBigNumbers (a, b) {
var res = '', c = 0;
a = a.split('');
b = b.split('');
while (a.length || b.length || c) {
c += ~~a.pop() + ~~b.pop();
res = c % 10 + res;
c = c > 9;
}
return res;
//Extend the String object with toBase64() and fromBase64() functions
String.prototype.toBase64 = function () {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
let result = '';
let i = 0;
while (i < this.length) {
let a = this.charCodeAt(i++) || 0;
let b = this.charCodeAt(i++) || 0;
let c = this.charCodeAt(i++) || 0;
function add() {
var c = 1000000000;
var args = Array.prototype.slice.call(arguments);
var sum = 0;
for (var i = 0; i < args.length; i++) sum += args[i] * c;
return (sum / c).toString();
}
const parseInt = string => {
var n = 0,
g = 0;
function text2num(s) {
const a = s.toString().split(/[\s-]+/);
a.forEach(feach);
return n + g;
}
function toChineseNumeral(num) {
var numerals = {
"-":"负",
".":"点",
0:"零",
1:"一",
2:"二",
3:"三",
4:"四",
5:"五",
const determinant = m => {
const l = m.length;
if (l === 1) return m[0][0];
if (l === 2) return m[0][0] * m[1][1] - m[1][0] * m[0][1];
let result = 0;
for (let i = 0; i < l; i++) {
result += Math.pow(-1, i) * m[0][i] * determinant(minor(m, i, 0));
}
return result;
const regexDivisibleBy = n => {
if (n == 1) return '^(0|1)+$';
if (n == 2) return '^(0|1)+0$';
if (n == 3) return '^(0*(1(01*0)*1)*)*$';
if (n == 4) return '^(0|1)+00$';
if (n == 5) return '^(0|1(10)*(0|11)(01*01|01*00(10)*(0|11))*1)+$';
if (n == 6) return '^(0|(11|1(00|011*0)(00|011*0)*1)(11|1(00|011*0)(00|011*0)*1)*0)+$';
if (n == 7) return '^(0|(10((0|11)(1|00))*(10|(0|11)01)|11)(01*0(0|101|1(1|00)((0|11)(1|00))*(10|(0|11)01)))*1)+$';
if (n == 8) return '^(0|1)+000$';
}
function regexDivisibleBy(n) {
if (n==1) return '^[01]+$' // Special case
let a = [] // List of nodes
for (let i=0; i<n; i++) a[i] = {} // Node
for (let i=0; i<n; i++) {
a[i].id = i // Used for indentification below
a[i][i*2%n] = '0' // Keys in nodes are id refs to other nodes
a[i][(i*2+1)%n] = '1' // Values in nodes are the required chars to get to next node (the key)
}
const decodeMorse = morseCode => morseCode
.trim()
.split` `
.map(e => morseDictionary[e])
.join``
.replace(/\s+/g, ' ');
const morseDictionary = {
'...---...': 'SOS',
'-.-.--': '!',
/**
* [1,2,3].equals([1,2,3]); // true
* [1,2,3].equals([1,2]); // false
* [1,2,3].equals([1,2,4]); // false
* [1,2,3].equals("123"); // false
* Array.prototype.equals.call("123", "123"); // true
* Array.prototype.equals.call("123", [1,2,3]); // false
* [1,2,3].equals([1,2,{value: 3}], (x, y) => (x.value || x) === (y.value || y)); // true
*/
Array.prototype.equals = function (other, callback = (x, y) => (x === y)) {