Category "arrays"

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,

Laravel - Attribute casting does not cast serialised value to array

I have a model in which I have the following cast: protected $casts = [ 'formatted_criteria' => 'array' ]; It is stored in the database as a seriali

Find third largest no in Java

I'm little confused with this simple program.I have to find third largest no in array.I have done some code but getting only second largest no problem in third

Cannot use "a" (type string) as type in array element in go

I'm pretty new to Golang and I have an issue with adding items to Array. I use this link as a reference golang-book. I have this struct: package models type Fi

PHP if in_array() how to get the key as well?

Struggling with a tiny problem. I have an array: Array ( [0] => [6] => 6 [3] => 5 [2] => 7 ) I am checking if a set value is in

I'm getting item.map is not a function when I try to delete an item with filter

I'm having a difficult time knowing why when I try to delete an item, it gives me a items.map() is not a function. Before I added the delete functionality, it w

Reversing an array using a stack

I am attempting to reverse an array using a stack. However, I get an error on arr[i] = stack.top();, and the suggestion to resolve it in Eclipse is to change it

Find common objects in multiple arrays by object ID

I've searched SO for a way to do this but most questions only support two arrays (I need a solution for multiple arrays). I don't want to compare exact objects

How to find NaN in an array and stop once found?

Say, I want a routine to stop once a not-a-number is found in an array. How can I do this? if (array(i) .eq. NA) ... seems not work. The array is an array of fl

How to separate range of integers into two equal parts

I have an array of integers like this one int [] num = {5, 8, 1, 1, 2, 3, 2} and I want to divide it into 2 parts, so that the total of 2 sets will be as equ