added javascript version. obviously more concise