convert to javascript, add test case