Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [iteration]

Iteration is the repetition of a block of statements within a computer program, usually with mutable state.

15
votes
5answers
1k views

Count Even Digits In Number

I was asked to complete this CodeStepByStep problem. Here's a quick summary: Write a function named count_even_digits that accepts two integers as parameters ...
1
vote
1answer
45 views

Check if a web element has a specific property and apply changes to the DOM according to the property's existence

I wrote this Javascript snippet for a Polymer fronted, it works without issues. The only thing that it accomplishes is changing an icon's orientation whenever a user is clicking on any expandable-...
0
votes
1answer
61 views

Grouping objects that have the same attributes

A list of objects needs to be grouped. The list is iterated and checked with other objects in the same list except itself. The method People.isAttributeEqual() checks if two objects can be grouped. ...
2
votes
2answers
49 views

N-Repeated Element in Size 2N Array

The task is taken from leetcode In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times. Return the element repeated N times. ...
2
votes
3answers
75 views

Find non-duplicated integer in a list where every integer occurs three times except for one integer

The task Given an array of integers where every integer occurs three times except for one integer, which only occurs once, find and return the non-duplicated integer. For example, given [6,...
4
votes
1answer
95 views

Walking over a N branching tree

The aim of this code, written in Python3.6, was to write a function that will non-recursively walk over a N-branching tree structure. It works by using a list of indices that keep track of visited ...
3
votes
2answers
64 views

A Java Iterable over multiple arrays

GlueArrays is used for iterating over an array of arrays, and it looks like this: Main.java ...
2
votes
2answers
39 views

Iterating through two objects with different structures in parallel

I have two objects, one input = Array<Type> and one stored = Array<{..., Type}> What's the best (cleanest) way to ...
2
votes
1answer
68 views

Write a function that adds two numbers stored in a linked list and returns the sum

Just for fun I did the following exercise from "Cracking the coding interview. 4th edition": You have two numbers represented by a linked list, where each node contains a single digit. The digits ...
3
votes
3answers
96 views

Check if a postcode is in a list

I'm looking for improvement / advice / reviews on how I can improve this code. I feel like there is a better way or more efficient way of doing this and I am over looking it. The Plugin I made is ...
3
votes
0answers
13 views

IDL code for minimum distance calculation

I made a program in IDL for performing a minimum distance classification on multispectral satellite data. This is what my main function looks like: ...
2
votes
1answer
77 views

Creating objects from xml-data

I've got an XML file with some info about hosts connected to my home network and I would like to create objects containing that info in a neat way, so that I can make some nice front-end application ...
2
votes
0answers
30 views

Speed up iteration for large dataset in python

I'm trying to parse data into a csv prior to a bulk transaction into Neo4j. I'm using vast amounts of data in the relationships and wondered if anyone could help in speeding up the transactions below....
2
votes
1answer
68 views

Web scraping JSON-data from API put into Dataframe

The web-scraping process currently takes quite a bit of time, and I wonder if I can structure the code otherwise or improve it in any way. Code looks like this: ...
19
votes
7answers
8k views

FizzBuzz in Javascript

I'm sure everyone here knows what FizzBuzz is. I would like constructive criticism for my solution. I'm a beginner to programming as a whole and this isn't my first solution, but it's what I think is ...
4
votes
3answers
141 views

Java Magic square program

Here is my improved version of my Magic square program from following this earlier version. I also added a few comments. Any help for improvements would be really appreciated. ...
0
votes
1answer
39 views

Generating probability table of 2-character combinations from text file in Java

I have written a probability table generator in Java to help me generate randomized girl's names for the game I am making. It reads from a text file and creates a ...
3
votes
2answers
56 views

Storing statistics as JSON in a simulation game

I am working on a choice-based simulation and players have to choose between different locations, I am pushing those choices to an array locationLog and my ...
2
votes
3answers
90 views

Extracting data in ES6

I have this array const idArray = ["12", "231", "73", "4"] and an object ...
1
vote
6answers
2k views

Elegantly exclude part of an operation for the last iteration in a loop [closed]

I'm afraid just about everybody who read this question has misunderstood it. I'm not trying to find the best way of printing a vector. I'm trying to find the best way of excluding part of an operation ...
2
votes
1answer
35 views

Finding the Original Fractions from Rounded Decimals

The data I'm using is summoning rates from a gacha game, One Piece Treasure Cruise. The game provides the probability of getting a certain character in percents rounded to the nearest thousandth. ...
2
votes
2answers
60 views

Collect members from custom tree nodes

In my program, I have a tree of Group nodes, each identified by their ImportId. Each group has zero or more members, that I ...
3
votes
1answer
58 views

Toggle Event Delegation

NOTE: the Javascript is all I'm concerned about, the HTML/CSS is just DEMO code. One caveat is ARIA states or attributes, if you have input on that, by all means, dive in. I had the need for and ...
1
vote
1answer
85 views

Short Ruby program that opens a random video file from a directory

I am currently learning to code in ruby. I have created a small program that iterates through a directory of video files and opens one at random. The program is fully functioning (with the odd issue). ...
3
votes
1answer
146 views

C++ inorder traversal of binary tree

The challenge was to create a function which performs an in order traversal without using recursion. What I came up with was to use a stack and some clever popping and pushing. I was wondering if ...
0
votes
1answer
32 views

Process CSV files that follow the first nonempty one

I have a list of CSV files (all have the same fields), some of which are empty. My goal is to find the first nonempty file and use that as the "base" file for an aggregation. After finding the base ...
2
votes
1answer
66 views

Iteratively simulate a parasite population

I'm trying to build a simulation in R to model the effects of different parasite egg laying behaviors on how many offspring the parasite has, given a limited amount of resources. In brief, this ...
3
votes
3answers
327 views

Effieciently validate multiple DataRows with return early option

I'm looking for an efficient way to validate multiple rows originating from multiple .csv files. Below is the current code to accomplish that. The validation logic is in the function ...
1
vote
1answer
41 views

Merging and summing multi-dimensional arrays

I've found myself today really struggling with this subject and I'm pretty sure that there must be a better way to do this. First of all my arrays have the same layout, I need to merge them and sum ...
3
votes
1answer
513 views

Plotting quadratic equations with varying parameters

On Wikipedia, there is a graph shown: It shows the quadratic \$y = ax2 + bx + c\$, varying each coefficient separately while the other coefficients are fixed (at values a = 1, b = 0, c = 0) As a ...
2
votes
1answer
155 views

Retrive relation on a polymorphic model

I have a Game model that is "static". Containing game information and such, and users can comment on all games. Games model <...
1
vote
4answers
145 views

Find value that occurs in odd number of elements

I am trying to solve the following exercise using Javascript: A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be ...
3
votes
1answer
41 views

D minMax function implementation

I happened to need to find both the maximum and the minimum of an array, so I decided to implement a minMax function in D. Questions: Is this an efficient ...
0
votes
1answer
60 views

VBA code which creates a daily report, based on data gathered in Worksheets in an Excel Workbook

I'm looking for some enlightening, since I'm still learning to code in VBA. I'm running code to create a daily report. It has to compare dates and check certain values in those dates and based on that ...
4
votes
2answers
3k views

Median Filter Implementation In Python

I implemented median filter in Python in order to remove the salt & pepper noise from the images. It is working fine and all but I would love to hear your advice or opinions. ...
4
votes
3answers
424 views

Using an offset variable to keep track of the next item in a Rust array

I am using an offset variable to track the iteration position, and modifying / returning it. Is the below considered bad practice in Rust? I ask this because I don'...
2
votes
1answer
2k views

Script to load controllers dynamically for AngularJS

I would like to hear your thoughts, idea's or feedback on the following code. Ive added to code to github. https://github.com/redbullzuiper/angularjs-dynamic-controllers Usually when you attach a ...
5
votes
1answer
2k views

Check if multiple lists contain an element from a large external list

I have a list of lists (many tokenised sentences). For anyone who doesn't know what tokenised sentences are, my list is like so: ...
2
votes
2answers
151 views

Iterative version of Hanoi Tower exercise

I just finished a iterative version of Hanoi Tower. This is how the algorithm works: I'm trying to find a method to delete the goto instruction. Any tips? ...
1
vote
1answer
52 views

Simple backtracking code

Is this good or can it be improved? The program should backtrack the two variables until this logic operation is true: a & b. ...
1
vote
2answers
6k views

Iterate two lists and find matches

I have 2 lists with varying length. Both lists contain data which has to be matched with entries from the other list. Currently I am iterating both lists with a nested ...
10
votes
1answer
4k views

Remove all values duplicates from list

I'm new to programming in general, started on boxing day. I'm trying to learn python. The list remove method only removes the first instance of the value found. In the code below I attempted to ...
8
votes
2answers
1k views

Interleave two lists of strings

I've got a fairly simple task here, but I think it's worth trying to perfect the implementation, because I can probably learn a thing or two about using .NET's enumerables correctly in the process. I ...
6
votes
1answer
84 views

A database of books, part 1

Backstory I collect books. A lot of books. Whitepapers, (programming) cookbooks, transcripts, important letters, overviews, you name it. Usually in PDF, otherwise my house would be too small. To ...
5
votes
0answers
65 views

Comparing the size of tumors over time using PANDAS

I have a dataframe in pandas like this ...
4
votes
1answer
515 views

Check if two date ranges overlap by X minutes

I have a list of volunteer shifts. The shifts are time ranges- for example, 9AM-2PM and 12PM-5PM. I need to check by how many minutes multiple selected shifts overlap, and then throw an error if the ...
11
votes
10answers
5k views

Tests for palindromes in C and C++

A question I've been asked on interactive phone screens is to code a test to determine whether a string is a palindrome or not. I am providing two examples here: one in C and one in C++. They both ...
2
votes
1answer
1k views

find the index of subarray from a parent array

Are there any improvements that can be made on the below code, especially in terms of memory and time? I feel bad about setting found = false in every iteration of ...
1
vote
1answer
1k views

Checks size of and number of files in each subdirectory

The code snippet here checks in every folder for subfolders, and stores the sub-sub folders This is my sample directory structure. I want to read through every sub-folders to find the number of files ...
5
votes
1answer
2k views

Iterative in-place quicksort

I have implemented an iterative in-place quicksort algorithm in Python, which by default selects the pivot as the last element: ...