Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
What does the .filter(i => i) do in this case?

I'm reading the process being built on

https://developers.cardano.org/docs/integrate-cardano/listening-for-payments-cli/#process-utxo-table

and I'm stuck on the results of this part:

// Calculate total lovelace of the UTXO(s) inside the wallet address
const utxoTableRows = rawUtxoTable.data.trim().split('\n');
let totalLovelaceRecv = 0;
let isPaymentComplete = false;

for (let x = 2; x < utxoTableRows.length; x++) {
    const cells = utxoTableRows[x].split(" ").filter(i => i);
    totalLovelaceRecv += parseInt(cells[2]);
}

I understand that up to the .split(" ") part, the table has been split into at least 2 items within the array of utxoTableRows since the first row the headers that we aren't interested in and the second row is the first utxo being processed. The .split(" ") then splits the row where there is a space but I don't know what the filter part does. The query utxo table looks as follows:

TxHash TxIx Amount
dfb99f8f103e56a856e04e087255dbaf402f3801acb71a6baf423a1054d3ccd5 0 1749651926

As you can see there are two rows. I'm completely lost at the filter component. I get more lost in the following command parseInt(cells[2]). I know somehow it takes the amount as a string and converts to integer. The [2] reference throws me off because wouldn't it have to be [3] since the amount is the 3rd item that gets split in that row? The only thing I can think of is that the .filter(i => i) throws out the TxHash, then saves the TxIx (in this case 0) in cell[1] and the amount (in this case 1749651926) in cell[2], both as strings.

Thank you for the help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

filter will filter out all items in the array where the callback returns false after coercion.

In this case, the filter removes all blank strings in the array. If the item is an empty string, the callback returns false, since empty strings, when coerced to a boolean, are false (see: Falsy values).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!