Войдите или зарегистрируйтесь
Вы сможете писать комментарии и посты, ставить лайки и другое
Поиск
Тёмная тема

Misleading naming in JavaScript: atob() and btoa()

5 дн. назад
JavaScript has two globally available metods for working with Base64: atob() and btoa(). Their names clearly look like they were borrowed from older languages. In C, for instance, the standard library includes functions like atoi and atof:

#include <stdlib.h>

char str[] = "123";
int num = atoi(str); // 123

atoi means ASCII to integer, and atof means ASCII to float (though in reality it returns a double).

So what do you think the atob function does in JavaScript? ASCII to Base64? In other words, converting a regular string into a Base64 string? Nope! It does the exact opposite: it converts a Base64 string into a "regular" string. And btoa, in turn, converts a regular string into Base64!

console.log(btoa('Famabara')); // 'RmFtYWJhcmE='
console.log(atob('RmFtYWJhcmE')); // 'Famabara'

Who thought it was a good idea to swap the names like that? Love JS.
+1
6

Sometimes restrictions create beauty in architecture

24 дн. назад
Restrictions don't always lead to something bad. Let's look at the Blue Mosque in Istanbul - it is adorned with stunning patterns, yet there are no images of people or other living beings, because this is prohibited by Islamic norms. The restriction influenced the architecture, resulting in interiors like these:
Or take Amsterdam as an example. At one time, taxes in the city depended on the width of a building's façade, so future homeowners constructed rather narrow but tall houses. As a result, a distinctive Amsterdam architectural style emerged.
Показать полностью...
+2
6

The expectation paradox: he wanted a boy, but kept having girls

недавно
A man has five children - all girls. He dreams of a son, an heir! Now his wife is pregnant again. Let's skip the psychology behind all this and focus on the probabilities.

Emotionally, it feels like after five girls in a row, a boy is due. Surely, the odds of finally having a son are much higher now.

But this is a textbook example of the gambler's fallacy - the false belief that if something happens repeatedly, the opposite is bound to happen soon. That's not how probability works.

According to math, the chance of having exactly five girls in a row followed by another girl is 1 in 64, or about 1.6%. But those five girls are already here. The only thing that matters now is the next birth.

And the odds of having a boy? Still 50/50. Every birth is an independent event (assuming randomness), so the previous outcomes don't change the next one.

So yes, there's still a 50% chance they'll have another girl.
+3
61