refactoring to make it simple without many if The 2019 Stack Overflow Developer Survey Results...
Why is the maximum length of OpenWrt’s root password 8 characters?
Earliest use of the term "Galois extension"?
Can one be advised by a professor who is very far away?
How to save as into a customized destination on macOS?
Why isn't airport relocation done gradually?
What does ひと匙 mean in this manga and has it been used colloquially?
What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?
When should I buy a clipper card after flying to OAK?
Why isn't the circumferential light around the M87 black hole's event horizon symmetric?
Time travel alters history but people keep saying nothing's changed
What is the closest word meaning "respect for time / mindful"
Is there a symbol for a right arrow with a square in the middle?
Button changing it's text & action. Good or terrible?
A poker game description that does not feel gimmicky
Identify boardgame from Big movie
How come people say “Would of”?
Can someone be penalized for an "unlawful" act if no penalty is specified?
Loose spokes after only a few rides
For what reasons would an animal species NOT cross a *horizontal* land bridge?
Which Sci-Fi work first showed weapon of galactic-scale mass destruction?
Geography at the pixel level
How to notate time signature switching consistently every measure
What to do when moving next to a bird sanctuary with a loosely-domesticated cat?
What is the motivation for a law requiring 2 parties to consent for recording a conversation
refactoring to make it simple without many if
The 2019 Stack Overflow Developer Survey Results Are InIn AngularJS, create lots of directives or use ng-controller?Cleaning up a dining hall…websiteToo many conditions in the methodJavaScript plugin architecture for multiple methods with the same parametersSimple code refactoring in javascriptImrpove the following code without if/elseNodeJS/Express/socket.io backendSimple JavaScript front-end framework for building web componentsVue - It's the Royal Game of UrSpawning multiple child processes to preview Vue.js projects
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
I have this piece of code in my repository of nodejs.
Criteria is huge but I have cut it short to keep the question simple.
there are lot of if conditions, which I don't really like... wondering what is best way to refactor it to more simple and to the point...
const {
a,
b,
} = criteria;
const bindings = { a: `${a}` };
if b!== '') {
bindings.b = `${b}%`;
}
.... if conditions keep going depending on the long criteria, I just skips those part to cut the question short
..
...
const optionalWhere = `
${(b !== '') ? ' AND b LIKE :b' : ''}
`;
const result = await this.knex.raw(`SELECT blah blah
WHERE a = :a
${optionalWhere}
`, bindings);
javascript node.js
New contributor
$endgroup$
add a comment |
$begingroup$
I have this piece of code in my repository of nodejs.
Criteria is huge but I have cut it short to keep the question simple.
there are lot of if conditions, which I don't really like... wondering what is best way to refactor it to more simple and to the point...
const {
a,
b,
} = criteria;
const bindings = { a: `${a}` };
if b!== '') {
bindings.b = `${b}%`;
}
.... if conditions keep going depending on the long criteria, I just skips those part to cut the question short
..
...
const optionalWhere = `
${(b !== '') ? ' AND b LIKE :b' : ''}
`;
const result = await this.knex.raw(`SELECT blah blah
WHERE a = :a
${optionalWhere}
`, bindings);
javascript node.js
New contributor
$endgroup$
add a comment |
$begingroup$
I have this piece of code in my repository of nodejs.
Criteria is huge but I have cut it short to keep the question simple.
there are lot of if conditions, which I don't really like... wondering what is best way to refactor it to more simple and to the point...
const {
a,
b,
} = criteria;
const bindings = { a: `${a}` };
if b!== '') {
bindings.b = `${b}%`;
}
.... if conditions keep going depending on the long criteria, I just skips those part to cut the question short
..
...
const optionalWhere = `
${(b !== '') ? ' AND b LIKE :b' : ''}
`;
const result = await this.knex.raw(`SELECT blah blah
WHERE a = :a
${optionalWhere}
`, bindings);
javascript node.js
New contributor
$endgroup$
I have this piece of code in my repository of nodejs.
Criteria is huge but I have cut it short to keep the question simple.
there are lot of if conditions, which I don't really like... wondering what is best way to refactor it to more simple and to the point...
const {
a,
b,
} = criteria;
const bindings = { a: `${a}` };
if b!== '') {
bindings.b = `${b}%`;
}
.... if conditions keep going depending on the long criteria, I just skips those part to cut the question short
..
...
const optionalWhere = `
${(b !== '') ? ' AND b LIKE :b' : ''}
`;
const result = await this.knex.raw(`SELECT blah blah
WHERE a = :a
${optionalWhere}
`, bindings);
javascript node.js
javascript node.js
New contributor
New contributor
New contributor
asked 5 mins ago
DeveloperDeveloper
1011
1011
New contributor
New contributor
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Developer is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217237%2frefactoring-to-make-it-simple-without-many-if%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Developer is a new contributor. Be nice, and check out our Code of Conduct.
Developer is a new contributor. Be nice, and check out our Code of Conduct.
Developer is a new contributor. Be nice, and check out our Code of Conduct.
Developer is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217237%2frefactoring-to-make-it-simple-without-many-if%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown