Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ternary logic #75

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions code/examples/ternary-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

## 📝 코드 예시

다음 코드는 `A조건`과 `B조건`에 따라서 `'BOTH'`, `'A'`, 또는 `'NONE'` 중 하나를 `status`에 지정하는 코드예요.
다음 코드는 `A조건`과 `B조건`에 따라서 `"BOTH"`, `"A"`, `"B"` 또는 `"NONE"` 중 하나를 `status`에 지정하는 코드예요.

```typescript
const status =
A조건 && B조건 ? "BOTH" : 둘다아닌경우 ? "NONE" : A조건 ? "A" : undefined;
(A조건 && B조건) ? "BOTH" : (A조건 || B조건) ? (A조건 ? "A" : "B") : "NONE";
```

## 👃 코드 냄새 맡아보기
Expand All @@ -27,14 +27,9 @@ const status =

```typescript
const status = (() => {
if (A조건 && B조건) {
return "BOTH";
}

if (A조건) {
return "A조건";
}

if (A조건 && B조건) return "BOTH";
if (A조건) return "A";
if (B조건) return "B";
return "NONE";
})();
```
25 changes: 10 additions & 15 deletions en/code/examples/ternary-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ Using complex ternary operators can obscure the structure of the conditions, mak

## 📝 Code Example

The following code assigns `'BOTH'`, `'A'`, or `'NONE'` to `status` based on `ACondition` and `BCondition`.
The following code assigns `"BOTH"`, `"A"`, `"B"`, or `"NONE"` to `status` based on `ACondition` and `BCondition`.

```typescript
const status =
ACondition && BCondition
(ACondition && BCondition)
? "BOTH"
: NotBoth
? "NONE"
: ACondition
? "A"
: undefined;
: (ACondition || BCondition)
? (ACondition
? "A"
: "B")
: "NONE";
```

## 👃 Smell the Code
Expand All @@ -33,14 +33,9 @@ You can rewrite the conditions using `if` statements, as shown below, to make th

```typescript
const status = (() => {
if (ACondition && BCondition) {
return "BOTH";
}

if (ACondition) {
return "A";
}

if (ACondition && BCondition) return "BOTH";
if (ACondition) return "A";
if (BCondition) return "B";
return "NONE";
})();
```