Use javascript to implement some algorithem for interview