FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Shaving some bytes with reduce by robinvdvleuten · Pull Request #8 · developit/dlv · GitHub

/ dlv Public

Shaving some bytes with reduce - #8

Open
robinvdvleuten wants to merge 1 commit into
developit:masterfrom
robinvdvleuten:master
Open

Shaving some bytes with reduce#8
robinvdvleuten wants to merge 1 commit into
developit:masterfrom
robinvdvleuten:master

Conversation

Copy link
Copy Markdown

Hi there! By using an array reduce on the key, you'll can go even leaner with 124 bytes 💪

Copy link
Copy Markdown

Unfortunately, after minification, using reduce is actually larger (using https://jscompress.com/ which uses UglifyJS 3 and Babili):

original (119 bytes):
export default function dlv(a,b,c,d){for(d=0,b=b.split?b.split('.'):b;a&&d<b.length;)a=a[b[d++]];return a===void 0?c:a}

with reduce (123 bytes):
export default function dlv(a,b,c){return(a=(b.split?b.split('.'):b).reduce(function(d,e){return d&&d[e]},a))===void 0?c:a}

Copy link
Copy Markdown
Owner

Thanks for the great explanation @kevlened! This also jives with my experience. Worth noting that performance is also at play here, and reduce() has fairly poor performance.

This file contains hidden or 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL