I am trying to convert the following C# function into Javascript, but I haven\'t had much luck (see my attempt below).
Original C# code:
using System;