# folder check

• through jquery checks for a folder

``````for (var i=1;i<=100;i++){
\$.post( "http://192.168.100.67/vtnuft/group"+i+"/check.php", function(response){
response = JSON.parse(response);
\$.each(response, function( key, val ) {
if(key === "check" && val === true){
console.log(key,val,i);
informationArray.push(i);}
else if(key === "check" && val === false){
console.log(i,"false");
}
});
});
}
``````

But informationArray keeps 101 times as long as it's found a whisper. _

What's the reason for this?

• Problem is, you use the same variable i in every circuit that changes. In order to preserve the variable &apos; s importance, a new context must be created by calling for an anonymous function.

This is one way:

``````for (var i=1; i<=100; i++)
!function(i) {
// \$.post(... и т.д.
}(i);
``````

What kind of magic is going on here?

`function(i) { ... }` - this is an anonymous function that receives a parameter `i`♪ This parameter covers the external variable. `i`

`function(i) { ... }(i)` - it's a challenge to the declared anonymous function, with the variable value transferred to it. `i` Like a parameter. Now inside the function of the parameter `i` equal to the value of the variable `i` at the time of the call. Now the cycle can go further, the variable value `i` change by 101, but within an anonymous function, the parameter value `i` It's not gonna change.

`!function(i) { ... }(i)` - it's one way to write the last version so the interpreter understands it's an expression. The point is, if the line begins with the word `function` - The interpreter will consider it to be a specific function, and there will be a syntax error. To avoid this, any operation is added to the expression.

Such design options are also acceptable:

• `~function(i) { ... }(i)`
• `+function(i) { ... }(i)`
• `-function(i) { ... }(i)`
• `1/function(i) { ... }(i)`
• `(function(i) { ... })(i)`
• `(function(i) { ... }(i))`

Another option is to take the anonymous function not of the whole cycle body, but only of the reversal challenge to be transmitted `\$.post`:

``````for (var i=1; i<=100; i++)
\$.post("http://192.168.100.67/vtnuft/group"+i+"/check.php", function (i) {
return function (responce) {
// ...
}
}(i))
``````

There's an anonymous function that's not at the very beginning of the line, and that's why there's no need for any tricks. Choose the option you like.

2

2

2

2

2

2

2

2

2

2

2

2

2

2

2
{"ft_lang_label":"__label__en","ft_lang_prob":0.6924754,"math_prob":0.97008646,"size":2770,"snap":"2022-27-2022-33","text_gpt3_token_len":700,"char_repetition_ratio":0.14750542,"word_repetition_ratio":0.019693654,"special_character_ratio":0.30469313,"punctuation_ratio":0.19464286,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9643302,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-12T12:11:37Z\",\"WARC-Record-ID\":\"<urn:uuid:5893c16d-4a45-48d0-8428-a94ea463409f>\",\"Content-Length\":\"191795\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:394df04a-c41b-4395-a0ec-f2d2297aeb41>\",\"WARC-Concurrent-To\":\"<urn:uuid:e1f85f46-a179-432a-87a2-1962ca3e78f2>\",\"WARC-IP-Address\":\"64.227.85.145\",\"WARC-Target-URI\":\"https://software-testing.com/topic/868900/folder-check\",\"WARC-Payload-Digest\":\"sha1:AD7L7FEGIT2ZRZKXME7I2ALVGYLPC7VD\",\"WARC-Block-Digest\":\"sha1:5VCHS4FFWIMVS437WRHQPNVTAVRNGBO5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882571692.3_warc_CC-MAIN-20220812105810-20220812135810-00119.warc.gz\"}"}