All Questions
10 questions
3
votes
1
answer
400
views
What is the expected performance of While loops using `array.pop()` assignment vs other methods
Recently I was asked to refactor some code that leverages JavaScript's array.reduce() method because other developers felt the code hard to read. While doing this I decided to play around with some ...
1
vote
0
answers
42
views
is it better to have tracking fields that are maintained separately for arrays? [duplicate]
I wasn't sure exactly how to word this question, but basically, I have a struct stNeuralLayers (for a neural network I'm playing around with) with fields that are matrices (such as a double[,] ...
2
votes
2
answers
186
views
Should special case be inside or outside the for loop here?
For example, suppose I have 2 arrays:
let arr1=[5,2,1];
let arr2=["abcde","ab","a"];
my work is simple : to check if length of strings in arr2 are larger than corresponding element with same index in ...
3
votes
2
answers
126
views
Should I move tasks which is just for a specific element only out of for loop?
For example, I have a for loop, which element 0 has additional function to run compared with other elements, my question is, should the additional function be:
1.place inside for loop
for(int i=0;i&...
9
votes
2
answers
11k
views
Is it good practice to use array.pop() assignment in a while loop condition?
Just saw a code snippet that used an array pop assignment in the while condition; was wondering if this is acceptable/good practice?
var arr = [0,1,2,3,4,5];
var current;
while (current = arr.pop())
{...
-3
votes
1
answer
4k
views
Using System.out.println() with loops and arrays [closed]
Is there anyway I can create a loop for System.out.println("...") and reading in the values? For example I wish to do this:
System.out.println("Input the Executive's name: ");
String eName = ...
-1
votes
1
answer
194
views
eradicating the array = loop mindset [closed]
I have noticed a common issue in code reviews, that takes this form:
// "arr" is an array
for (i = 0; i < arr.length; ++i) {
if (i == 3) {
// do something with arr[i]
}
if (i ==...
85
votes
3
answers
44k
views
How do I move away from the “for-loop” school of thought?
This is a rather conceptual question, but I was hoping I could get some good advice on this. A lot of the programming I do is with (NumPy) arrays; I often have to match items in two or more arrays ...
3
votes
3
answers
1k
views
Is there a way to add unique items to an array without doing a ton of comparisons?
Please bare with me, I want this to be as language agnostic as possible becuase of the languages I am working with (One of which is a language called PowerOn). However, most languanges support for ...
0
votes
3
answers
25k
views
2 Dimensional Arrays in C++
I started learning arrays in C++ and came over a little side note in the book talking about 2D arrays in breif.
I tested it out and i was amazed that it could give the programmer the ability to store ...