Zian
g/javascript

Da się wsadzić znak z pozycji w tablicy w Regexie? Jakaś metoda na zliczenie wystąpień znaku z pozycji w tablicy?

let str = "onomatopoeia";
str = str.match(/o/g);
console.log(str.length); // 4

Deykun
g/Architektura

https://streamable.com/yzawz4

94% of the dorm's single occupancy rooms are in the interior of the building, and have no windows.
[...]
A consulting architect on the university's Design Review Committee quit in protest of the project, in a resignation letter obtained by CNN Business and reported by the Santa Barbara Independent.
 
"The basic concept of Munger Hall as a place for students to live is unsupportable from my perspective as an architect, a parent and a human being," California architect Dennis McFadden wrote in the letter. McFadden declined further comment to CNN Business.
[...]
In addition to being Warren Buffett's right-hand man, Munger is an amateur architect. He has no formal education in the field.
 
Munger, the 97-year-old vice chairman of Warren Buffet's Berkshire Hathaway, donated $200 million to UCSB to fund the dorms, with the caveat that his designs are followed. He wanted the dorm rooms to be tiny and windowless to encourage residents to spend more time outside in the common areas, meeting other students.

Plan pietra:
https://pyxis.nymag.com/v1/imgs/59f/c88/9f96fe911305f463140fa68e44ed268cf4-ucsb-dorm-plan.2x.rhorizontal.w700.jpg

https://edition.cnn.com/2021/10/29/business/ucsb-munger-hall/index.html

Zian

@Deykun: Jeszcze takie sztuczne okno i można by mieszkać:

https://www.thisiscolossal.com/2015/02/artificial-sunlight-system/

kakabix
g/ModernClassical

Kupiłem sobie dżinsy z dziurami
Jestem dobre kilka lat za modą
Ale może chociaż one
Trochę mnie odmłodzą

Zian

@kakabix: Dobra wentylacja zawsze w modzie.

https://d-art.ppstatic.pl/kadry/k/r/1/68/85/58cbd308edfcc_o_large.jpg

Zian
g/javascript

Dlaczego wartość str jest zwracana przy n = -1?

function padIt(str, n) {
while (n--) str = (n & 1) ? (str + "*") : ("*" + str);
return str;
}

console.log(padIt("a", 5));

EDIT: Wcina wcięcia.

Zian

@Deykun: Coś takiego działa:

function padIt(str, n) {
    str = str.padStart(str.length + Math.ceil(n / 2), "*");
    str = str.padEnd(str.length + Math.floor(n / 2), "*");
    return str;
}

console.log(padIt("a", 9));

Zian
g/javascript

Dlaczego wartość str jest zwracana przy n = -1?

function padIt(str, n) {
while (n--) str = (n & 1) ? (str + "*") : ("*" + str);
return str;
}

console.log(padIt("a", 5));

EDIT: Wcina wcięcia.

Zian

@spam_only: Dopiero co to odkryłem, ale i tak wolę for loop.

Zian
g/javascript

Dlaczego wartość str jest zwracana przy n = -1?

function padIt(str, n) {
while (n--) str = (n & 1) ? (str + "*") : ("*" + str);
return str;
}

console.log(padIt("a", 5));

EDIT: Wcina wcięcia.

Zian

@sens: Wtedy tak, ale chodziło mi o to, że n osiąga -1.
@spam_only: Spoko, wiem jak działa pętla, ale musiałem sobie uświadomić, że tam osiągane jest while(0), czyli false.

Zian
g/javascript

Dlaczego wartość str jest zwracana przy n = -1?

function padIt(str, n) {
while (n--) str = (n & 1) ? (str + "*") : ("*" + str);
return str;
}

console.log(padIt("a", 5));

EDIT: Wcina wcięcia.

Zian

we fajerfoksie

@sens: Hmm. https://i.imgur.com/1nc83OJ.png

Zian
g/javascript

Dlaczego wartość str jest zwracana przy n = -1?

function padIt(str, n) {
while (n--) str = (n & 1) ? (str + "*") : ("*" + str);
return str;
}

console.log(padIt("a", 5));

EDIT: Wcina wcięcia.

Zian

@ajdajzler: Jak działają, to wiem, ale wyjaśnienie jest takie, że gdy osiągnie 0, wtedy while(0) będzie false i zakończy pętlę. Sprawdziłem i w C działa to tak samo.

Zian
g/javascript

Dlaczego wartość str jest zwracana przy n = -1?

function padIt(str, n) {
while (n--) str = (n & 1) ? (str + "*") : ("*" + str);
return str;
}

console.log(padIt("a", 5));

EDIT: Wcina wcięcia.

Zian

@ajdajzler: Czyli w takiej składni pętla zatrzyma się na 0. Dobry patent, chociaż nadal nie wiem dlaczego tak jest.

Zian
g/javascript

Dlaczego wartość str jest zwracana przy n = -1?

function padIt(str, n) {
while (n--) str = (n & 1) ? (str + "*") : ("*" + str);
return str;
}

console.log(padIt("a", 5));

EDIT: Wcina wcięcia.

Zian

@Deykun: Tu nie chodzi o operacje na bitach.

function padIt(str, n) {
while (n--) {
    str = (n % 2 === 0) ? ("*" + str) : (str + "*");
}
return str;
}

console.log(padIt("a", 5));

Jeśli reszta z dzielenia n przez 2 jest równa 0, dodaj gwiazdkę po lewej stronie od str, inaczej po prawej. n jest równe 5, a potem kolejno schodzi do -1.

Zian
g/javascript

Dlaczego wartość str jest zwracana przy n = -1?

function padIt(str, n) {
while (n--) str = (n & 1) ? (str + "*") : ("*" + str);
return str;
}

console.log(padIt("a", 5));

EDIT: Wcina wcięcia.

Zian

no nie wiem, mi wywala out of memory

@sens: W czym to uruchamiasz?

https://edube.org/sandbox/157592ee-3580-11ec-90e0-0242157e55ca

Also, przejedz ten kod w JS Tutor:
https://pythontutor.com/javascript.html#mode=edit

Zian
g/javascript

Dlaczego wartość str jest zwracana przy n = -1?

function padIt(str, n) {
while (n--) str = (n & 1) ? (str + "*") : ("*" + str);
return str;
}

console.log(padIt("a", 5));

EDIT: Wcina wcięcia.

Zian

Tak średnio pełna.

Zian

@Aleks: Skaczę i klaskam.

Zian

Tak średnio pełna.

Stary telewizor zakł...

Stary telewizor zakłócał łącze DSL codziennie przez 18 miesięcy [ENG]

Zakłócenie wykryto analizatorem widma.

0 comments Internet Zian arstechnica.com 0