Skip to content

Instantly share code, notes, and snippets.

@ybigus
Created October 28, 2014 17:28
Show Gist options
  • Save ybigus/b6357b322b06d1b6b95c to your computer and use it in GitHub Desktop.
Save ybigus/b6357b322b06d1b6b95c to your computer and use it in GitHub Desktop.
var womanHeightList = [155,157,160,163,165,168,170,171,173,175,178,180,183];
var increaseButtonStream = $('.btn-size.add').asEventStream('click');
var decreaseButtonStream = $('.btn-size.delete').asEventStream('click');
var counterStream = increaseButtonStream.map(1).merge(decreaseButtonStream.map(-1)).scan(0, function (acc, x){
var sum = acc + x;
if (sum<0) sum = womanHeightList.length-1;
if (sum>womanHeightList.length-1) sum = 0;
return sum;
});
var counterTextStream = counterStream.map(function(value){
return womanHeightList[value];
});
var imageHeightStream = counterStream.map(function(value){
var humanHeight = womanHeightList[value] * pxPerSm;
return humanHeight;
});
counterTextStream.assign($('.current-height'), 'text');
imageHeightStream.assign($('.human'), 'height');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment