How to convert this Pascal Code to JavaScript? -


I am trying to create a ZS code that determines the number of 1 to 9 in a string. I have this Pascal Code that works:

  Var n, i: longint; A: array [0..9] byte; Start typing ('Ð ?? вÐÐ'ÐÑÑÑ? Ðμ Ñ ?? ÐÑÑ ?? Ð »Ð¾:'); Ridleyn (N); While n & gt; Start 0 [n mod 10]: = A [n mod 10] +1; N: = n div 10; End; For the Eye: = 0 to 9, Rictoran ('number', ',' is, a [i], 'quantity of time'); Readln; End. In JS I ended up with it but it seems that there is never ending loop:  
  function plush (form) {var list = New Array (9); Var n = form.a.value; While (n> gt; 0) {a = n% 10; List [a] = List [A] +1; N = n% 10; } For (var i = 0; i & lt; = 9; i ++) {warning ("Ð Ð Ð Ñ Ñ" Ð ° "+ i +" Ð²Ñ ?? Ñ ?? Ñ ?? ÐμÑÑ ?? Ð ° ÐμÑÑ ?? Ñ ± [i] + "n ?? Ð ° Ð ·");}}   

I will get any help about this Thanks in advance!

n = n% 10 Leaves n as soon as it is less than 10 , it will never reach 0 , hence an endless loop. / P>

Change

  n = n% 10   

  n = Math. Floor ( N / 10);   

You also have one more problem: You are not starting your array properly so that you can add 1 to undefined . Fix it: < Function (ploy) {var a, list = [], n = form.a.value; while (n> gt; 0) {a = n% 10; List [one] = (list [one] || 0) +1; n = Math for floor (N / 10);} (var i = 0; I & lt; = 9; I ++) {console.log ("Ð | Ð - ÑÑ" Ð ° "+ i +" Ð²Ñ ?? Ñ ?? Ñ ?? ÐμÑ ?? Ð ° ÐμÑÑ ?? Ñ ?? Ñ ?? " + A [i] + "n ?? Ð ° Ð ·"); // & lt; - less painful than warning}}

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -