Всем доброго! Помогите пожалуйста перевести этот код с Delphi в javascript:
unit ipscrpt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Dialogs, StdCtrls;
function IpsEncodeString( source: string ): string;
function IpsDecodeString( source: string ): string;
type
arr = array[0..9, 0..9] of integer;
const mas1: arr = (
(1, 2, 3, 6, 0, 8, 5, 4, 7, 9),
(2, 1, 8, 6, 5, 9, 7, 0, 4, 3),
(7, 6, 1, 5, 8, 4, 2, 9, 3, 0),
(2, 6, 5, 7, 4, 0, 8, 1, 3, 9),
(0, 8, 6, 2, 7, 9, 4, 5, 3, 1),
(5, 7, 8, 0, 6, 9, 2, 4, 3, 1),
(0, 6, 5, 3, 8, 7, 1, 2, 9, 4),
(9, 7, 8, 6, 3, 0, 1, 5, 2, 4),
(1, 0, 5, 9, 2, 7, 3, 6, 4, 8),
(6, 2, 9, 4, 1, 0, 8, 5, 3, 7)
);
const mas2: arr = (
(4, 0, 1, 2, 7, 6, 3, 8, 5, 9),
(7, 1, 0, 9, 8, 4, 3, 6, 2, 5),
(9, 2, 6, 8, 5, 3, 1, 0, 4, 7),
(5, 7, 0, 8, 4, 2, 1, 3, 6, 9),
(0, 9, 3, 8, 6, 7, 2, 4, 1, 5),
(3, 9, 6, 8, 7, 0, 4, 1, 2, 5),
(0, 6, 7, 3, 9, 2, 1, 5, 4, 8),
(5, 6, 8, 4, 9, 7, 3, 1, 2, 0),
(1, 0, 4, 6, 8, 2, 7, 5, 9, 3),
(5, 4, 1, 8, 3, 7, 0, 9, 6, 2)
);
implementation
function IpsEncodeString( source: string ): string;
var
i,j,k: integer;
begin
for i:=length(source) downto 1 do
if not(source[i] in ['0'..'9']) then delete(source,i,1);
result := '';
i := 0;
j := 0;
while (i <= Length(source) - 1) do begin
k := mas1[j, StrToInt(source[i+1])];
result := result + IntToStr(k);
inc(i);
inc(j);
if (j>=10) then j := 0;
end;
end;
end;
end.
Мне нужна именно
IpsEncodeString . функция.
Delphi вижу в первый раз, на первый взляд ничего сложного, но чтото у меня не получается....