Category "arrays"

Sum all odd indexes in an array

I have to complete a program according to these instructions: public class SumOddIndex { public static void main(String[] args){ int[] array = {1,1,

Sum all odd indexes in an array

I have to complete a program according to these instructions: public class SumOddIndex { public static void main(String[] args){ int[] array = {1,1,

Codewars Challenge - Count of positives / sum of negatives

My code works but it's not being accepted in order to pass the challenge. Any help on what I'm doing wrong would be appreciated. Challenge Description: Given

The ArraySort callback is not sorting my array in the correct order

Using ColdFusion to sort an multi-dimensional array based on a "Price per sq. ft" field from high to low. It has been in production and worked in testing, but

Return multiple values from a function using mysqli_fetch_assoc [closed]

How do I return multiple values from the array returned from mysqli_fetch_assoc() in the code below? function db_query($sql){

Javascript remove all occurrence of duplicate element, leaving the only one that is unique

I want to remove elements that occurr more than once and get the unique element. The array always has 3 elements. Lets say i have an array [2,3,2], then I need

Javascript. Reduce an array by adding only odd numbers. Javascript returns NaN when I use %2 on a number with if [duplicate]

I am trying to sum all odd numbers of an array. The following method does not work and returns NaN. Could someone explain me why? I found a wo

General approach to modifying an array while looping through it

Is it safe in Perl6 (as opposed to perl5 or other languages) to loop through an array while modifying it? For instance, if I have an array of websites to downlo

Given a sequence of integers, return the sum of all the integers that have an even index, multiplied by the integer at the last index

This is my solution and it passes some of the tests, but not all of them. Can anyone help me and explain why? Thank you :) function evenLast(numbers) { let su

Dividing arbitrary large numbers stored in char arrays in C

A part of my home assignment requires dividing large integers that are so long I can only store them in character arrays. Both the divident and the divisor can

PHP -> Next nearest date defined by array of days in week

please, really need help with this problem. I have array of offerDays - $offerDays = array(1,6); (mean Monday, and Saturday); For example, input date is Wedne

JQuery get table row values from input and save to array

I have a table with input fields inside the td. How can i get the values from the input fields (by button click) and store them into an array (one row) using JQ

How to zip every element of array to every element of another array in ruby?

Say I have this array: [0, 1, 4], [2, 3] How can I merge them to get: [0,2], [0,3], [1,2], [1,3], [4,2], [4,3] I tried: [0, 1, 4].zip [2, 3] But I got:

Extending Array to check if it is sorted in Swift?

I want to extend Array class so that it can know whether it is sorted (ascending) or not. I want to add a computed property called isSorted. How can I state the

Search for array row with specific column value and return another value from qualifying row

I have a multidimensional array that I am trying to search for a specific value (url) and then retrieve an another value in the same row (value). I also need to

ARRAY_AGG() grouped by another column's values

Here's my table like below p_no type name value ------------------------ 1 A Tomy 1 1 A Nick 2 1 B Tomy 3 1 B Nick 4 1

Sum similar keys in an array of objects

I have an array of objects like the following: [ { 'name': 'P1', 'value': 150 }, { 'name': 'P1', 'value': 150 }

Using JavaScript need to group elements

I am looking for efficient method to modify my object list which looks something like this: const pets = [ {type:"Dog", name:"Spot"}, {type:"Cat"

Vue JS returns [__ob__: Observer] data instead of my array of objects

I've created a page where I want to get all my data from the database with an API call, but I'm kinda new to VueJS and Javascript aswell and I don't know where

How to add names to a numpy array without changing its dimension?

I have an existing two-column numpy array to which I need to add column names. Passing those in via dtype works in the toy example shown in Block 1 below. With