// Called on page load and when the user clicks on 1 of the four buttons
function FindPromo() {
var checkExist = setInterval(function () {
var length = $('table.tst-orderProductsTable').find('tbody').children().length;
if (length > 0) {
clearInterval(checkExist);
$('tbody').scroll(function () {
$('.promotion').filter(checkVisible).addClass('promoSelect'); // Find all promotion td's and assign promoSelect class to them
GetPromo();
}).scroll();
}
}, 500);
}
function checkVisible() {
var elm = this;
var eval = eval || "visible";
var vpH = $(window).height(), // Viewport Height
st = $(window).scrollTop(), // Scroll Top
y = $(elm).offset().top,
elementHeight = $(elm).height();
if (eval == "visible") return ((y < (vpH + st)) && (y > (st - elementHeight)));
}
// Now loop the td's and find all td's that have the class promoSelect.
// Then retrieve information from that td
function GetPromo() {
var product_description = '';
var product_position = '';
$("td").each(function (i, row) {
if ($(this).hasClass('promoSelect')) {
console.log("here");
}
});
}
// clicking 1 of the four buttons above table.
$('.product-tab-label').click(function () {
FindPromo();
});
FindPromo();
,F :: * -> *
和iterate' :: Ord a => (a -> a) -> a -> F a
是否包含以下属性?
elem' :: Ord a => Int -> a -> F a -> Bool
⇒elem x (take n (iterate f y))
⇒elem' n x (iterate' f y)
elem x (iterate f y)
在elem' n x (iterate' f y)
时间和O(n * log n)
空间中运行
O(n)
在elem' n x xs
时间和O(log n)
空间中运行
答案 0 :(得分:5)
import qualified Data.Set as S
type F x = [S.Set x]
iterate' f
= map head
. evalState (traverse (state . splitAt) (iterate (*2) 1))
. scanl (flip S.insert) S.empty
. iterate f
elem' n x xs = S.member x $ xs !! (ceiling (logBase 2 (fromIntegral n)) - 1)
(中间集是否算作分配空间?如果你需要平衡它们,你甚至可以在线性空间中做有限集吗?)