attempted implementation on .NET in javascript