From f16df917b0d50150e990a919a6af416306ec7d57 Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Tue, 28 Jan 2020 08:06:04 +0100 Subject: [PATCH] Add more principles. --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index 573b6ad..cb55012 100644 --- a/README.md +++ b/README.md @@ -100,3 +100,46 @@ _Bad 👎🏻_ let ingredients = ['tomato', 'onion', 'mushrooms']; let dressings = ['ketchup', 'mayonnaise']; ``` + +### 💩 Triangle principle + +Be like a bird - nest, nest, nest. + +_Good 👍🏻_ + +```javascript +function someFunction() { + if (condition1) { + if (condition2) { + asyncFunction(params, (result) => { + if (result) { + for (;;) { + if (condition3) { + } + } + } + }) + } + } +} +``` + +_Bad 👎🏻_ + +```javascript +function someFunction() { + if (!condition1 || !condition2) { + return; + } + + const result = await asyncFunction(params); + if (!result) { + return; + } + + for (;;) { + if (condition3) { + } + } +} +```