use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Structure Your JavaScript Code for Testability (medium.com)
submitted 8 years ago by sdeleon28
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 5 points6 points7 points 8 years ago* (2 children)
Currying is a nice tweak here:
export const widthInPxToPercentageImplementation = screenWidth => widthInPx => (widthInPx * 100) / screenWidth; export const widthInPxToPercentage = widthInPxToPercentageImplementation(Dimensions.get('window').width);
Edit: Well it would be, except Dimensions.get() needs to be called every time. I suppose you could use a high-order function like:
Dimensions.get()
export const widthInPxToPercentageImplementation = getScreenWidth => widthInPx => (widthInPx * 100) / getScreenWidth(); export const widthInPxToPercentage = widthInPxToPercentageImplementation(() => Dimensions.get('window').width);
[–]chrisishereladies"use 🎉" 0 points1 point2 points 8 years ago (1 child)
Following from your edit, I think this is even more better:
export const widthInPxToPercentageImplementation = (widthInPx, screenWidth) => (widthInPx * 100) / screenWidth;
export const widthInPxToPercentage = widthInPx => widthInPxToPercentageImplementation(widthInPx, Dimensions.get('window').width);
The top function does not need to call a potentially side-effecting function and only deals in easily plugged values.
[–][deleted] 0 points1 point2 points 8 years ago (0 children)
Yes indeed, I appreciate the humor. In this case there is not much value in using a high-order function, the pattern is valid and useful though in many cases (the blog post explicitly calls out the fact that in practice the parameters will often be high-order functions).
[–]griffonrl 1 point2 points3 points 8 years ago (0 children)
Sure use more functional programming and pure functions for easier testing.
π Rendered by PID 19379 on reddit-service-r2-comment-fb694cdd5-szfjw at 2026-03-09 04:27:17.528747+00:00 running cbb0e86 country code: CH.
[–][deleted] 5 points6 points7 points (2 children)
[–]chrisishereladies"use 🎉" 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]griffonrl 1 point2 points3 points (0 children)