Skip to content

Instantly share code, notes, and snippets.

@NoFishLikeIan
Created April 11, 2019 17:54
Show Gist options
  • Save NoFishLikeIan/aedea07632d5bb7b518175679fe3c125 to your computer and use it in GitHub Desktop.
Save NoFishLikeIan/aedea07632d5bb7b518175679fe3c125 to your computer and use it in GitHub Desktop.
Some funny pixels operations
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