- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
type a = 1;
type i = a & a;
type j = a | a;
function main() {
let v1: i;
let v2: j;
assert(sizeof(i) != sizeof(j));
print("done.");
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
type a = 1;
type i = a & a;
type j = a | a;
function main() {
let v1: i;
let v2: j;
assert(sizeof(i) != sizeof(j));
print("done.");
}
ну все я понял вам скучно... как насчет такого примера?
−1
type int = 1;
type int64 = 4294967296;
declare function GC_get_heap_size(): int64;
function main() {
let i = 0;
for (i = 0; i < 10000000; ++i) {
const p = new int[1];
if (i % 100000 == 0) print("Heap size = ", GC_get_heap_size());
}
}
вот такая лабуда подкатили.. называется GC.. для тех кто не любит GC я добавил опцию -nogc :)
вот так можно JIT запускать без компиляции
tsc.exe --emit=jit --shared-libs=TypeScriptGCWrapper.dll 1.ts
tsc.exe --emit=jit -nogc 1.ts
0
function main() {
const o = {
v: "Hi",
toString() {
return this.v;
},
};
print(o);
}
Хочу напомнить о себе, а то люди начали забывать :)...
+7
console.log(parseInt(0.5)); // 0
console.log(parseInt(0.05)); // 0
console.log(parseInt(0.005)); // 0
console.log(parseInt(0.0005)); // 0
console.log(parseInt(0.00005)); // 0
console.log(parseInt(0.000005)); // 0
console.log(parseInt(0.0000005)); // 5
https://ideone.com/YMWUGq
Возможно баян, спижжено с https://vk.com/wall-72495085_1267978
+2
type int = 1;
function makeRangeIterator(start = 0, end = 10000, step = 1) {
print("makeRangeIterator.");
let nextIndex = start;
let iterationCount = 0;
const rangeIterator = {
next() {
let result: [value: int, done: boolean];
if (nextIndex < end) {
result = [nextIndex, false];
nextIndex += step;
iterationCount++;
return result;
} else {
result = [iterationCount, true];
}
return result;
},
};
return rangeIterator;
}
function main() {
let it = makeRangeIterator(1, 10, 2);
let result = it.next();
while (!result.done) {
print(result.value); // 1 3 5 7 9
result = it.next();
}
print("done.");
}
Ну вот и все... позвольте мне представить самый сложный кусок когда либо компилированный моей программой. но ввиду того что "трамплины" хрен знает как работают то придется этот код "забанить" до лучших времен. Но он рабочий
+2
class S
{
print()
{
print("Hello World");
}
}
interface IPrn
{
print();
}
function run(iface:IPrn)
{
iface.print();
}
function main() {
const s = new S();
let iface = <IPrn>s;
iface.print();
run(s);
}
короче новый говнокод подоспел. Т.к. вы все тут самые умные я не раскажу в чем фича. Сами догадаетесь
+2
type int = 1;
function main() {
let result: [value: int, done: boolean];
let v: int | undefined;
v = 1;
result = [v, false];
print(result[0], result[1]);
assert(result[0] == 1);
assert(result[1] == false);
}
опа. новый говнокодец подоспел. а кто знает какая проблема решалась в данном коде?
+2
function foo(arg: any) {
if (typeof arg === "string") {
// We know this is a string now.
print(arg);
}
}
function main() {
foo("Hello");
foo(1);
print("done.");
}
наговнокодил
+1
function foo(arg: any) {
if (typeof arg === "string") {
// We know this is a string now.
print(<string>arg);
}
}
function main() {
foo("Hello");
foo(1);
print("done.");
}
я вам новый говнокодец притарабанил.... вот будете как настоящие жабаскриптеры в нативе
+5
function call_func_1(
f: () => void
) {
f();
}
function call_func(
f: (o: object) => void,
user: { firstName: string }
) {
f(user);
}
function main() {
const user = {
firstName: "World",
sayHi() {
print(`Hello ${this.firstName}`);
},
};
user.sayHi();
const hi = user.sayHi;
hi();
let hi2 = user.sayHi;
hi2();
call_func_1(() => {
hi2();
});
call_func(user.sayHi, user);
print("done.");
}
как тебе такой говно-пиздец Илон Маск?