Created
April 11, 2019 17:54
-
-
Save NoFishLikeIan/aedea07632d5bb7b518175679fe3c125 to your computer and use it in GitHub Desktop.
Some funny pixels operations
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 sumPixels(pixelA, pixelB) { | |
var first = parseInt(pixelA.replace('px', '')) | |
var second = parseInt(pixelB.replace('px', '')) | |
return `${first+second}px` | |
} | |
function multiplyPixels(pixelString, factor) { | |
var f = Math.floor(factor) | |
var remainder = f ? factor % f : factor | |
var remainderPixel = `${remainder}px` | |
var pixels = '0px' | |
// Nice ✨! | |
while(f-- > 0) { | |
pixels = sumPixels(pixels, pixelString) | |
} | |
var initPixels = parseFloat(pixelString.replace('px', '')) | |
// Double nice! ✨ | |
while (initPixels-- > 0) { | |
pixels = sumPixels(pixels, remainderPixel) | |
} | |
return pixels | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment