Category "arrays"

Binary search program cause runtime error and failed hidden test cases

I am practicing binary search with problem 704 on leetcode. At first, I just follow the concept of binary search and came up with this solution: int search(int*

How to sort array of objects by dates and make new arrays which will contain all objects with same date [closed]

I have a very specific problem in Javascript. I have array of objects, and each object contains some date. const array = [ {name: 'first', dat

How can update values in an array of objects?

how to get new array newSelect using map ,forEach const selects = [false, true, true, true, false]; const oldSelects = [ { select: true, name: 'AA' },

TypeError: state.find is not a function

I try to use the find() method but I get cartItems.find is not a function what happens? and how to fix it? import React, {useState} from 'react' function car

How to sort array in constant time in java and python?

I was trying to learn algos and data structures, and i was wondering about best approach to sort arrays in constant time. I am newbie but my only intention is t

Implode columnar values between two arrays into a flat array of concatenated strings

I have two arrays, $array_A and $array_B. I'd like to append the first value from $array_B to the end of the first value of $array_A and repeat this approach fo

Delete an item(Object) from an array using ng-if

I am trying to remove item using ng-if and ng-else-if. "ng-if="navItem.gbn.indexOf('12345') !== -1" is true then array item only show contains('12345') items. b

Group data in a multidimensional array based on two columns

I have an indexed array of associative arrays like this: [ ['brand' => 'ABC', 'model' => 'xyz', 'size' => 13], ['brand' => 'QWE', 'model' =&

Most efficient way of showing or calling repeat/duplicate HTML?

I have five div elements containing the same six images. Only one div is shown at a time (others are display:none) but all are on the same page. Basic example:

Logic of for loop using with array to access elements of the array in java

My code to access elements of array using for loop. The output of the program is [19,17,15] which are the elements of array int a[] = { 12, 15, 16, 17, 19, 23 }

extract longest non NaN sequence from array

I want to extract the longest sequence of consecutive non NaN values from an array in Python. So from this one: a = [NaN, NaN, NaN, 1, 4, NaN, NaN, NaN, 4, 6, 8

How can I remove the last comma from a map?

I have, { mydata.map(({ name }) => ( <p style = {{ display: "inline" }} > { " " } { name }, </p>)) } How can I remove the last c

Conways game of Life with 1D array

Right now I'm doing this tutorial for WebAssembly with Rust. The task is to implement Conways Game of Life in Rust. Writing a low-level language like Rust is ne

extract intensity profile along a line from image

ch4-out is the sample imageI have a numpy array that contains some image data (ch4_out). Now, I want to extract intensity profile along a particular line (horiz

How to make a array inside array?

I have this two array. I want to make a array inside an array like this. How can I achieve that. Code posted below. This is the image I am sending inside fileTo

How to convert array of objects into custom grouped array

I am trying to convert the data object to custom format This is my data which i want to convert [ { Name: 15, GroupID: 1, Id: 1 }, { Name: 16, GroupID: 1,

How to vectorize such an algorithm in python?

I have four (nx1) dimensional arrays named a, b, c, and F. I want to run this algorithm without any loops. for i in range(n): if a[i] < b[i]: F[i

how to find possible combinations

I have an array of 16 columns and 22 rows. please advice how to find all possible combinations with the following rules: I can't choose more than 1 value per ro

Is there a more functional way to merge and foreach/sort two arrays in TypeScript, React?

I'm learning React and TypeScript. For sake of practise, I've tried to create a calculator design by merging two arrays to map a single array onto the grid (dis

JavaScript sorting of an RGB array

This is the task: Colors have to be ordered in such way: Higher Red value first; if the same then: Higher Green value first; if the same then: Higher Blue val