🐒: if (a == 2) return true else return false

2023-06-16 17:09:25 +08:00
 idealhs

🤡: return a == 2 ? true : false;

return a == 2 😅:???

茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴茴

4267 次点击
所在节点    程序员
34 条回复
beijinglowb
2023-06-16 21:42:40 +08:00
@EscYezi rxjs 是这样的
cyrbuzz
2023-06-16 21:56:33 +08:00
!!!(2^a)
rabbbit
2023-06-16 23:19:42 +08:00
🐶
interface Is2Interface {
is2(a: number): boolean;
}

abstract class AbstractIs2 implements Is2Interface {
is2(a: number): boolean {
return a === 2;
}
}

class Is2 extends AbstractIs2 {
is2(a: number): boolean {
if (a === 2) {
return true
} else {
return false
}
}
}

interface Is2FactoryInterface {
getIs2(): AbstractIs2;
}

abstract class AbstractIs2Factory implements Is2FactoryInterface {
getIs2(): AbstractIs2 {
return new Is2();
};
}

class Is2Factory extends AbstractIs2Factory {
private is2: AbstractIs2 = new Is2();
getIs2(): AbstractIs2 {
return this.is2;
};
}

class Main {
public static main(): void {
const is2Factory = new Is2Factory();
const is2 = is2Factory.getIs2();
const a = 2;
console.log(is2.is2(a));
}
}

Main.main();
proxychains
2023-06-16 23:26:20 +08:00
@rabbbit 这是更是重量级
ochatokori
2023-06-16 23:45:10 +08:00
return a !== 2 ? false : true
fzls
2023-06-16 23:53:29 +08:00
@rabbbit 设计模式大师啊
tt7
2023-06-17 00:35:56 +08:00
SilentRhythm
2023-06-17 01:43:38 +08:00
for (int i =0; i < a; i = i *a) {
return true;
}
return false;
wwbfred
2023-06-17 02:02:18 +08:00
这是在和编译器较劲还是在给编译器 debug😂
liuidetmks
2023-06-17 09:34:33 +08:00
和讨论 i+++++i 等于几 异曲同工

竟然那么多回复,那种帖子不说回复,打开都是浪费时间
pengtdyd
2023-06-17 09:45:29 +08:00
在 scala 这里甚至 return 都不需要写
a == 2 就行了
FaiChou
2023-06-17 09:50:19 +08:00
swift 也一样,不用 return
2NUT
2023-06-17 15:44:51 +08:00
人类自以为是语法糖高级,在编译器优化看来都是一样的
idealhs
2023-06-17 15:57:46 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/949367

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX