JavaScript for math curve