Skip to content

Instantly share code, notes, and snippets.

@kilmc
Last active September 13, 2017 19:17
Show Gist options
  • Select an option

  • Save kilmc/476ae72fd61d83589b2d0f13b0ee22a1 to your computer and use it in GitHub Desktop.

Select an option

Save kilmc/476ae72fd61d83589b2d0f13b0ee22a1 to your computer and use it in GitHub Desktop.
const intersection = (arr1, arr2) => arr1.length > arr2.length
? arr1.filter(x => arr2.includes(x))
: arr2.filter(x => arr1.includes(x))
const getFactors = (number) => Array
.from(Array(number), (_, i) => i)
.filter(i => number % i === 0)
const calculateRatio = ([width, height]) => {
const gcf = Math.max(...intersection(getFactors(width),getFactors(height)))
return [width/gcf,height/gcf]
}
const calculateRatioHeight = ([width, height]) => (height/width)*100;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment