Created
April 23, 2019 17:42
-
-
Save SanjeQi/9496d395efe2daef6b997daadde61986 to your computer and use it in GitHub Desktop.
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
Get the average pixels | |
function getAveragePixels(cssObj) { | |
return Object | |
.values(cssObj) | |
.filter(el => el.includes('px')) | |
.map(el => parseInt(el)) | |
.reduce((acc, nr, index, array) => acc = (acc + nr) / array.length) | |
} | |
getAveragePixels({ | |
marginLeft: '6px', | |
marginBottom: '4px', | |
overflow: 'hidden', | |
position: 'fixed' | |
}) === 5; | |
getAveragePixels({ | |
paddingTop: '10px', | |
display: 'block', | |
paddingLeft: '20px' | |
}) === 15; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment