Category "for-loop"

Codility CyclicRotation Javascript Solution: Empty array returns an error

I am trying to solve this problem in codility. My solution passed all the tests except for one with empty array and rotation of 1 as arguments. I'm someway lost

Program to find number of elements between two elements a and b (where a and b both are inclusive)

Given an unsorted array of size n, write a program to find number of elements between two user-defined elements a and b (where a and b both are inclusive) of a

How do I efficiently find which elements of a list are in another list?

I want to know which elements of list_1 are in list_2. I need the output as an ordered list of booleans. But I want to avoid for loops, because both lists have

Mutiple iterators in for loop Java not working properly

I am trying to pass a Javascript code to Java, but I've got a problem with the for loop, I have a for with 2 iterators in my Javascript code, and it is working

Octave - fskipl: invalid stream number

I've got the error message: "Invalid parameter list" from my function, which let Octave open a text file and read it to get input data for my work. function [m

Python: For loops print only last element of a list

I am using a shared webspace and I can't install the dotenv libiary for php, but I can use the dotenv libiary for python to call enviorment variables from outsi

Python Count Letters in Word

I am looking to complete this code but cannot get it to execute the right way. The program connects two user-inputted names into one full name and then looks fo

IndexError: list index out of range in for loop

I write a code in python but I faced this error : if a1[i] == a1[i+1] == a1[i+2]: IndexError: list index out of range I write an if condition that if my list l

Codewars Challenge - JavaScript - Find the first non-consecutive number in Array

Link to Codewars challenge This is very basic, but for some reason, I can't figure out why I'm not able to return null when there are not any non-consecutive n

Python single plot in a for loop without creating a list or array

This may sound like a very naive question. However, to me, it's quite fundamental: Can python plot variables without putting them into arrays or lists? I couldn

program to find the sum of the first N odd numbers

I'm trying to make a program that calculates the sum of the first N odd numbers. where N is the number of the first odd numbers (e.g. N=4, then the first odds a

Create new numpy array by duplicating each item in an array

I would like to create a new numpy array by repeating each item in another array by a given number of times (n). I am currently doing this with a for loop and .

How do you remove duplicate values in array in Python?

I have an array where each element is the mean of a set of random numbers. I want to be able to remove duplicate values in this array. How would I go about doin

Function to see if word is isogram

An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only le

How to find or count the duplicate in multidimensional array in c# [closed]

I am creating a 2d (3 * 3) array in c# which has to count or find the duplicate value int[,] arr = new int[3, 3] { {1, 2, 6}, {4, 1, 5}

How to start iterating a file at specific line?

I’m iterating through a file’s lines with enumerate(), and sometimes would need to start the iterating at a specific file line, so I attempted testf

How to get value printed on Postgres

I have a requirement to translate it to an SQL script. I am using the information schema to get all the columns of a table and print their distinct count. I was

Using for loop in R to combine column values based on preceeding column conditions

I am working with a big dataset with multiple observations for a certain gene, on varying dates and with varying expression levels. Data used I would like to su

can I use partials in a for loop in ejs?

I'm trying to include partials in a for loop in EJS. <% let index = 1 %> <% for (let item in db) { %> <div class="box unfocused box_<

For loop not stopping and random generated number not being saved (number guessing game)

I'm doing a number guessing game in an Android app. You have three tries to guess the number. If you run out of trials, then you loose. I added a for loop so th