Skip to content

Instantly share code, notes, and snippets.

@goldhand
Created April 8, 2016 19:40
Show Gist options
  • Save goldhand/7c209c9200e8279937c10df9d2805abd to your computer and use it in GitHub Desktop.
Save goldhand/7c209c9200e8279937c10df9d2805abd to your computer and use it in GitHub Desktop.
returns a value from a set that meets conditions
function getActiveHeightTrigger(triggersMap) {
// returns the smalles height from a set of heights that is more than the window height
return triggersMap.reduce((pV, cV) => {
// is this height more than window?
let checkWindow = (cV.height >= window.innerHeight);
// is this height less than previous height?
let checkPrev = (cV.height < pV.height);
if (checkWindow) {
if (checkPrev || !pV.height) return cV;
}
return pV;
}, {});
}
let tTest = [
{
height: 615,
className: 'height-615',
},
{
height: 675,
className: 'height-675',
},
{
height: 715,
className: 'height-715',
},
{
height: 815,
className: 'height-815',
},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment