Javascript – How do I subtract the even positions from the odd ones in a 2D array and assign a new array with the results?

I've been stuck in this problem for days. I have a multidimensional array whose first position is a Date () object. I previously reduced the arrangement by grouping each day.
I try to reduce each daily subarray with the results of subtracting the odd positions ("SALIDA") of the pairs ("ENTRADA").

Here are the dates:

const arrayHoras = (
  (
    "Thu Jan 02 2020 08:25:38 GMT+0100 (CET)",
    "ENTRADA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Thu Jan 02 2020 13:30:43 GMT+0100 (CET)",
    "SALIDA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Thu Jan 02 2020 15:18:06 GMT+0100 (CET)",
    "ENTRADA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Thu Jan 02 2020 18:12:22 GMT+0100 (CET)",
    "SALIDA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Fri Jan 03 2020 08:35:38 GMT+0100 (CET)",
    "ENTRADA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Fri Jan 03 2020 10:15:23 GMT+0100 (CET)",
    "SALIDA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Fri Jan 03 2020 10:59:16 GMT+0100 (CET)",
    "ENTRADA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Fri Jan 03 2020 12:25:01 GMT+0100 (CET)",
    "SALIDA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Fri Jan 03 2020 12:31:33 GMT+0100 (CET)",
    "ENTRADA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Fri Jan 03 2020 13:20:43 GMT+0100 (CET)",
    "SALIDA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Fri Jan 03 2020 15:28:06 GMT+0100 (CET)",
    "ENTRADA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Fri Jan 03 2020 18:32:10 GMT+0100 (CET)",
    "SALIDA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Tue Jan 07 2020 08:31:46 GMT+0100 (CET)",
    "ENTRADA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Tue Jan 07 2020 13:22:51 GMT+0100 (CET)",
    "SALIDA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Tue Jan 07 2020 15:30:00 GMT+0100 (CET)",
    "ENTRADA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Tue Jan 07 2020 17:22:29 GMT+0100 (CET)",
    "SALIDA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Tue Jan 07 2020 17:31:59 GMT+0100 (CET)",
    "ENTRADA",
    "NOMBRE APELLIDO APELLIDO"
  ),
  (
    "Tue Jan 07 2020 18:32:30 GMT+0100 (CET)",
    "SALIDA",
    "NOMBRE APELLIDO APELLIDO"
  )
);

First step: We group the 2D arrangement by day of the first position of each element

const gruposDias = arrayHoras.reduce((acumulador, valorActual) => {
  const dia = new Date(valorActual(0)).getDate();
  if (!acumulador(dia)) {
    acumulador(dia) = ();
  }
  acumulador(dia).push(valorActual);
  return acumulador;
}, ());

const agrupadosPorDia = Object.keys(gruposDias).map(porDia => {
  return gruposDias(porDia);
});

Second step: I try to reduce the arrangements by day by subtracting the seconds between the data of the odd positions ("SALIDA") and those of the even positions ("ENTRADA"):

const entradas = ();
const salidas = ();
for (let i = 0; i < agrupadosPorDia.length; i += 1) {
  const agrupadosPorDiaI = agrupadosPorDia(i);
  for (let j = 0; j < agrupadosPorDiaI.length; j += 1) {
    if (j % 2) {
      const salidaTime = new Date(agrupadosPorDia(i)(j)(0)).getTime();
      salidas.push(salidaTime);
      rowSalida.push((ultRowConDatoSimulado += 2));
    } else {
      const entradaTime = new Date(agrupadosPorDia(i)(j)(0)).getTime();
      entradas.push(entradaTime);
    }
  }
}
console.log("entradas: ", entradas);
console.log("salidas: ", salidas);

My problem: With the second step, I lose the return of the "Entradas" and "Salidas" arrays within each subarray of the 2D array grouped by day.

Does anyone have the kindness to shed light on my decoder work?

If you misuse your knowledge, you can avoid the second step by expanding the array of the 2D array by expanding redu () and map (). I tried everything, I think.

Thank you in advance!!!.

magento 1.9 – How do I print an array in a stand-alone script into a CSV file?

Hello, I'm trying to save my array data in Magento 1.9 in CSV, where I retrieve all order details using a stand-alone script

my php script

getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
$orderCollection = Mage::getModel('sales/order')->getCollection();


foreach ($orderCollection as $order) {
        $orders('orders')() = array(
            'id'            => $order->getIncrementId(),
            'store'         => 'magento',
            'status'        => $order->getStatus(),
            'name'          => $order->getCustomerName(),
            'email'         => $order->getCustomerEmail(),
            'telephone'     => $order->getShippingAddress()->getTelephone(),
            'street'        => $order->getShippingAddress()->getStreet(),
            'pincode'       => $order->getShippingAddress()->getPostcode(),
            'city'          => $order->getShippingAddress()->getCity(),
            'weight'        => $order->getWeight(),


        );    

     foreach ($order->getAllItems() as $item) {
       $orders('orders')('items')() = array(
            'id'            => $order->getIncrementId(),
            'name'          => $item->getName(),
            'sku'           => $item->getSku(),
            'Price'         => $item->getPrice(),
            'Ordered Qty'   => $item->getQtyOrdered(),


        );

       $fp = fopen('test_export.csv', 'w');

foreach ($orders as $fields) {
    fputcsv($fp, $fields);
}

fclose($fp);

    }
    }
print_r($orders); 


echo "
"; print_r($orders);

Output:-

Array ( (orders) => Array ( (0) => Array ( (id) => 100000001 (store) => magento (status) => complete (name) => pramod mishra (email) => pramod.mishra@netsmartz.net (telephone) => 01234567890 (street) => Array ( (0) => plot no-10 ) (pincode) => 160101 (city) => chandigarh (weight) => 10.0000 ) (items) => Array ( (0) => Array ( (id) => 100000001 (name) => test (sku) => test (Price) => 10.0000 (Ordered Qty) => 1.0000 ) ) ) )

magento2.3 – Extracts the array string "qty" from the array in Magento 2

Have a code that gets the amount of Magento 2 product

class ClassName
{
    private $getSalableQuantityDataBySku;
    public function __construct(
        GetSalableQuantityDataBySku $getSalableQuantityDataBySku
    ) {
        $this->getSalableQuantityDataBySku = $getSalableQuantityDataBySku;
    }
    public function execute(MagentoFrameworkEventObserver $observer)
    {
        $sku = "testsimpleproduct1";
        $salable = $this->getSalableQuantityDataBySku->execute($sku);
        echo json_encode($salable);
    }
}

it is coming back

({"stock_name":"Default Stock","qty":4,"manage_stock":true})

How to extract the qty array value and pass it to

$data() = $product-> ......  

Excel – Google Sheets "array_agg" … or equivalent? (Join Match in Array)

I currently have that

=QUERY(
  QUERY(
    'Raw Paste'!C2:E, "select C, count(C) where C is not null group by C order by C label count(C) ''"
  ), "WHERE Col2 >= 2")

The second QUERY() This allows me to filter the aggregate function like an SQL HAVING Function…

This is what it does:

Enter image description here

But what I want to do is next to the count, I want a third column that connects the invoice numbers that are contained in the aggregate.

This would be trivial with ARRAY_AGG(C) But Google Sheets isn't that fancy.

I was thinking, maybe with INDEX/MATCH Somehow, but I don't know. I have to put the strings together if an element occurs more than once.

C    D
111  PPP
222  OOO
222  QQQ

Issue I want:

C    D
222  OOO, QQQ

product – Pass the function to the array in Magento 2.3

I have this code to get the quantity of items from the Magento 2.3 product

namespace HelloSourceItemDataModel;

use Exception;
use PsrLogLoggerInterface;
use MagentoFrameworkApiSearchCriteriaBuilder;
use MagentoInventoryApiApiDataSourceItemInterface;
use MagentoInventoryApiApiSourceItemRepositoryInterface;

class SourceItem
{
    /**
     * @var SearchCriteriaBuilder
     */
    private $searchCriteriaBuilder;

     /**
     * @var SourceItemRepositoryInterface
     */
    private $sourceItemRepository;

    /**
     * @var LoggerInterface
     */
    private $logger;

    public function __construct(
        SearchCriteriaBuilder $searchCriteriaBuilder,
        SourceItemRepositoryInterface $sourceItemRepository,
        LoggerInterface $logger
    ) {
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;
        $this->sourceItemRepository = $sourceItemRepository;
        $this->logger = $logger;
    }

    /**
     * Retrieves links that are assigned to $stockId
     *
     * @param string $sku
     * @return SourceItemInterface()
     */
    public function getSourceItemDetailBySKU(string $sku): array
    {
        $searchCriteria = $this->searchCriteriaBuilder
            ->addFilter(SourceItemInterface::SKU, '24-UB02')
            ->create();

        $result = $this->sourceItemRepository->getList($searchCriteria)->getItems();

        return $result;
    }
}

It's called that

$sku = '24-UB02';
$result = $this->getSourceItemDetailBySKU($sku);

foreach ($result as $item) {
    print_r($item->getData());
}

I want this code to get a set of articles and put them into an array. So I have to take care of it $data() = $product->..........

Any ideas?

Thanks a lot!

sql server – Get-Counter does not accept an array created from SQL

When I try to generate an array from SQL output, perfmon does not accept these values ‚Äč‚Äčeven though it is the same data type and content, whereas a manually created list is. The first call to Get-Counter returns an error message as shown below, with the second call working properly with a manually created list. How do I solve this?

 Get-Counter : Internal performance counter API call failed. Error: c0000bc4.

Line: 26 characters: 9

    $SQLQueryGetCounters  = "
    DECLARE @PerfmonCounterList VARCHAR(MAX) 
    SELECT 
        TOP 2
            PerfmonCounter
    FROM
        Perfmon.PerfmonCounterList"

    $SQLQueryGetCounters  = "
    DECLARE @PerfmonCounterList VARCHAR(MAX) 
    SELECT top 2
        ' `"' +PerfmonCounter + '`"' ItemValue 
    FROM
        Perfmon.PerfmonCounterList " 
    $Counters =   @(Invoke-sqlcmd -ServerInstance Localhost -Database "DatabaseMonitoring" -Query $SQLQueryGetCounters )| select-object -expand ItemValue
    $List = (System.Collections.ArrayList)@() # New-Object System.Collections.Generic.List(System.Object) # (System.Collections.ArrayList)@()

    foreach ($Item in $Counters)
        {
            $List.Add($Item)
        }

    $List = $List.ToArray()

    Get-Counter -Counter $List

     $List = "DATABASE(*)DATABASE CACHE % HIT","DATABASE(*)DATABASE CACHE SIZE (MB)"

     Get-Counter -Counter $List

Array – Check for subsets and remove this python

I tell them that I am on a python course and they gave us this exercise, I did it for many hours and the truth does not come out and I am new to the language, the exercise consists of:

Use the two lists of numbers "list_a" and "list_b" to identify whether A is a subset of B. In this case remove all elements from "list_a" that are present in "list_b".

I'll give you an example of what this function should do:

lista_a = (4, 7, 2)

lista_b = (9, 4, 6, 2, 10, 7)

extraer_subconjunto(lista_a, lista_b) 

This is what we call the function and the result should be the result: (9, 6, 10)

This is the code I made, but I don't get the result:

def extraer_subconjunto(lista_a, lista_b):
lista_c = ()
for i in lista_b:
    if i not in lista_a:
        lista_c.append(i)
    return lista_c

I get the following result: (4, 7, 2, 9) This is wrong. I hope you can guide me to find the solution. Thank you very much

Returns an object in an array that has the smallest value in a given Javascript key

Hi there!

I have the following array of objects:

const cores = (
    {cor: 'amarelo',
    peso: 2},
    {cor: 'amarelo',
    peso: 3},
    {cor: 'verde',
    peso: 7},
)

My goal is to filter it first so that it only returns objects with yellow, and I do that with:

const mani = obj.filter(spec => spec.cor === 'amarelo');

Then I have to filter this array so that only the brightest object returns me. This would be the expected object:

 {cor: 'amarelo', peso: 2},

How would I do it?

PHP – Split String String into an Array

The truth is that I have a problem dividing a string into a single array. For example, I have the following string:

etiqueta1_bg-warning, etiqueta2_bg-primary, etiqueta3_bg-success

And I have to divide it into an array like this:

0: "nombre_etiqueta" => etiqueta1,
    "color" => "bg-warning"

1: "nombre_etiqueta" => etiqueta2,
    "color" => "bg-primary"

2: "nombre_etiqueta" => etiqueta3,
    "color" => "bg-success"

And so on with the rest of the values, and then save the array in the database, which I also want to know how to do. I know that the explosion plays a fundamental role in the first step, but I only need an array. Not several in one. If someone can help me, it would be very helpful.