for-loop

Javascript for…of doesn't work in Safari

落花浮王杯 提交于 2020-01-13 12:06:57
问题 Currently I am trying to build a simple sidenavigation that appears/disappears whenever one of the "toggleSidenav" buttons is clicked (there are multiple). It seemed to work fine when testing with Firefox and Chrome but today when I tried to open my page with Safari (desktop and mobile version) the buttons didn't do anything. The problem seems to be the for-of-loop I used but checking the reference of the for...of, Safari should support it. My code: for (var btn of document

Javascript for…of doesn't work in Safari

隐身守侯 提交于 2020-01-13 12:06:50
问题 Currently I am trying to build a simple sidenavigation that appears/disappears whenever one of the "toggleSidenav" buttons is clicked (there are multiple). It seemed to work fine when testing with Firefox and Chrome but today when I tried to open my page with Safari (desktop and mobile version) the buttons didn't do anything. The problem seems to be the for-of-loop I used but checking the reference of the for...of, Safari should support it. My code: for (var btn of document

for( in ) loop index is string instead of integer

流过昼夜 提交于 2020-01-13 09:29:46
问题 Consider following code: var arr = [111, 222, 333]; for(var i in arr) { if(i === 1) { // Never executed } } It will fail, because typeof i === 'string' . Is there way around this? I could explicitly convert i to integer, but doing so seems to defeat the purpose using simpler for in instead of regular for -loop. Edit: I am aware of using == in comparison, but that is not an option. 回答1: You have got several options Make conversion to a Number: parseInt(i) === 1 ~~i === 1 +i === 1 Don't compare

How to rename the files in the path with new different names in batch?

人盡茶涼 提交于 2020-01-13 08:17:52
问题 I have one file destination.txt with path information about my CDs: C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SME99.ISO C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\Biomasse.iso C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SAMPE36.ISO Now I have to rename the ISOs with the numbers that are in the file PPN.txt one after another: 470692405 394006801 348117876 So it should be SME99.ISO -> 470692405.ISO Biomasse.iso -> 394006801.ISO Sampe36.ISO -> 348117876.ISO I have the

How to rename the files in the path with new different names in batch?

拥有回忆 提交于 2020-01-13 08:17:28
问题 I have one file destination.txt with path information about my CDs: C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SME99.ISO C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\Biomasse.iso C:\Users\NekhayenkoO\Desktop\LOG Dateien CD Imaging\SAMPE36.ISO Now I have to rename the ISOs with the numbers that are in the file PPN.txt one after another: 470692405 394006801 348117876 So it should be SME99.ISO -> 470692405.ISO Biomasse.iso -> 394006801.ISO Sampe36.ISO -> 348117876.ISO I have the

PHP - Foreach loops and ressources

和自甴很熟 提交于 2020-01-13 03:14:03
问题 I'm using a foreach loop to process a large set of items, unfortunately it's using alot of memory. (probably because It's doing a copy of the array). Apparently there is a way to save some memory with the following code: $items = &$array; Isn't it better to use for loops instead? And is there a way to destroy each item as soon as they have been processed in a foreach loop. eg. $items = &$array; foreach($items as $item) { dosomethingwithmy($item); destroy($item); } I'm just looking for the

Check std::vector has duplicates

一笑奈何 提交于 2020-01-12 18:50:35
问题 I want to check if a vector of integers has any duplicates or not, and have to return true if it does. So I try to do something like this: vector<int> uGuess = {1,2,3,3,4,5} vector<int> a = uGuess; sort(a.begin(), a.end()); bool d = unique(a.begin(), a.end()); And this will not work since unqiue cannot be assigned as a bool value. How should I proceed towards this? If I were to write a for loop to perform the same action, how should I do that? 回答1: Looking in google for std::unique I found

Check std::vector has duplicates

ⅰ亾dé卋堺 提交于 2020-01-12 18:49:48
问题 I want to check if a vector of integers has any duplicates or not, and have to return true if it does. So I try to do something like this: vector<int> uGuess = {1,2,3,3,4,5} vector<int> a = uGuess; sort(a.begin(), a.end()); bool d = unique(a.begin(), a.end()); And this will not work since unqiue cannot be assigned as a bool value. How should I proceed towards this? If I were to write a for loop to perform the same action, how should I do that? 回答1: Looking in google for std::unique I found

Check std::vector has duplicates

断了今生、忘了曾经 提交于 2020-01-12 18:49:45
问题 I want to check if a vector of integers has any duplicates or not, and have to return true if it does. So I try to do something like this: vector<int> uGuess = {1,2,3,3,4,5} vector<int> a = uGuess; sort(a.begin(), a.end()); bool d = unique(a.begin(), a.end()); And this will not work since unqiue cannot be assigned as a bool value. How should I proceed towards this? If I were to write a for loop to perform the same action, how should I do that? 回答1: Looking in google for std::unique I found

Check std::vector has duplicates

♀尐吖头ヾ 提交于 2020-01-12 18:49:33
问题 I want to check if a vector of integers has any duplicates or not, and have to return true if it does. So I try to do something like this: vector<int> uGuess = {1,2,3,3,4,5} vector<int> a = uGuess; sort(a.begin(), a.end()); bool d = unique(a.begin(), a.end()); And this will not work since unqiue cannot be assigned as a bool value. How should I proceed towards this? If I were to write a for loop to perform the same action, how should I do that? 回答1: Looking in google for std::unique I found