added javascript implementation