Last active
September 15, 2017 01:14
-
-
Save derek-knox/93c2f9020a82f4165b7f32956a0ff416 to your computer and use it in GitHub Desktop.
Decreasing LOC while maintaining clarity with ternary and bracket notation (1st Approach - 6 LOC from Kyle Simpson's Deep JS Foundations)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 1st Approach - 6 LOC */ | |
if(insertBefore) { | |
workElements[adjacentWorkEntryId].before($workEntry); | |
} | |
else { | |
workElements[adjacentWorkEntryId].after($workEntry); | |
} | |
/* 2nd Approach - 4 LOC (curly brace removal) */ | |
if(insertBefore) | |
workElements[adjacentWorkEntryId].before($workEntry); | |
else | |
workElements[adjacentWorkEntryId].after($workEntry); | |
/* 3rd Approach - 2 LOC (ternary replacing if/else and bracket notation replacing repetitive code */ | |
var method = insertBefore ? 'before' : 'after'; | |
workElements[adjacentWorkEntryId][method]($workEntry); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment