Category "arrays"

How to detect array start index by current shells (zsh/bash)?

We all know arrays in Bash are indexed from zero, and in zsh are indexed from one. How can the script know it should use 0 or 1 if I can't ensure the running en

How to detect array start index by current shells (zsh/bash)?

We all know arrays in Bash are indexed from zero, and in zsh are indexed from one. How can the script know it should use 0 or 1 if I can't ensure the running en

Inserting a key-value pair in a specified position of a JS Map object (akin to Array's .splice()) [duplicate]

Is there a way to performance-efficiently insert a key-value pair in a specific place of a Map object? The problem I'm trying to solve is sto

Best Way to Update/Edit an Array Element in SwiftUI

I have an array of identifiable Training elements. Each Training element only has two properties, name and isRequired. What is the most straight-forward (Swif

For each loop using 2D array

This is the snippet of Java code: int[][] uu = new int[1][1]; uu[0][0] = 5; for(int[] u: uu){ System.out.println(u[0]); } It prints 5. But why does the d

Find the Longest Subarray

Given an array of integers, what is the length of the longest subarray containing no more than two distinct values such that the distinct values differ by no mo

What is PHP's equivalent of JavaScript's "array.every()"?

I'm currently trying to port some JavaScript over to PHP. However, I can't seem to find PHP's equivalent to the JavaScript array.every() function. I found PHP's

How to go to next line after every row in a 2D array?

So I need to come up with something like this: It's a layout of seats on an airplane. 1 A B C D 2 A B C D 3 A B C D 4 A B C D 5 A B C D

Array to string conversion

$replacements = array( '{order_id}' => $order_id, '{site_url}' => $settings["site_url"], '{email}' => $user_email, '{last_name}' =&g

How to fill an Array conditionally?

I have the following JS code: let a = false let b = true let c = [...(a ? {d: 1} : {})] I'm trying to set c to [{d: 1}] if a is true, and set it to [] if a is

Declare a constant array

I have tried: const ascii = "abcdefghijklmnopqrstuvwxyz" const letter_goodness []float32 = { .0817,.0149,.0278,.0425,.1270,.0223,.0202, .0609,.0697,.0015,.0077

error: invalid use of non-static data member

class Stack { private: int tos; const int max = 10; int a[max]; public: void push(int adddata); void pop(); void pr

error: invalid use of non-static data member

class Stack { private: int tos; const int max = 10; int a[max]; public: void push(int adddata); void pop(); void pr

Flattening a list of strings and lists to work on each item [closed]

I am currently working with different input types - My input could either look like this: [term1, term2, term3,...] or [[term1, term2],

PHP's array_map including keys

Is there a way of doing something like this: $test_array = array("first_key" => "first_value", "second_key" => "second_value"); var

C++ concatenate two int arrays into one larger array

Is there a way to take two int arrays in C++ int * arr1; int * arr2; //pretend that in the lines below, we fill these two arrays with different //int values

Creating a simple inventory system in JavaScript

I'm trying to make a simple text adventure/farming simulator, but I'm new to JavaScript and I'm stuck trying to plan out how my inventory system will work. The

Writing To A Range Using VBA array

I have a script that pulls the first cell value of a table from a database and adds it 10 times. I want to write that list to excel. Here's what I have so far:

What is the C++ equivalent of Python's "in" operator?

What is the C++ way of checking if an element is contained in an array/list, similar to what the in operator does in Python? if x in arr: print "found" els

Find all subsets of length k in an array

Given a set {1,2,3,4,5...n} of n elements, we need to find all subsets of length k . For example, if n = 4 and k = 2, the output would be {1, 2}, {1, 3}, {1,