Created
September 21, 2020 21:52
-
-
Save jondcallahan/d92b62d4a96a7158a5a701f6921dfa14 to your computer and use it in GitHub Desktop.
Turns JavaScript using optional chaining back to duck typed `&&` syntax
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
function optToDuck(string) { | |
const parts = string.split("?."); | |
let duck = ""; | |
for (let i = 1; i <= parts.length;i++) { | |
for (let j = 0; j < i; j++) { | |
duck += `${parts[j]}` | |
if (j !== i -1) { | |
duck += '.' | |
} | |
} | |
if (i !== parts.length) { | |
duck += " && " | |
} | |
} | |
return duck; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment