arrays - Infinite For Loop - Javascript - Whats wrong? -


  फ़ंक्शन सॉर्टएरेरे (सरणी) {var tempArray = []; var tempNum; var tempPos; के लिए (var i = 0; i & lt; सरणी.लांबी; i + = 1) {if (i = 0) {tempNum = parseInt (सरणी [i]); tempPos = 0; } else if (parseInt (array [i]) & lt; = tempNum) {tempNum = parseInt (सरणी [i]); tempPos = i; } console.log (i); }}   

यह एक सरणी लेना चाहिए और इसे कम से कम सबसे बड़ा करने का आदेश दिया जाता है, लेकिन यह भी नहीं मिल पाता है क्योंकि के लिए लूप अनन्त हो जाता है। मैंने क्या किया?

आप i = 0 में सेटिंग कर रहे हैं पहले अगर, जिसका अर्थ है कि आप लूप से बाहर निकलने के लिए पर्याप्त नहीं होंगे I आप == के बजाय

अर्थात्:

  का उपयोग करना चाहते हैं यदि (i = 0) {tempNum = parseInt (array [i]); tempPos = 0; }   

होना चाहिए

  यदि (i == 0) {tempNum = parseInt (array [i]); tempPos = 0; }    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -