1

In my case

list A = [a,a,a,b,b,c]

I have to find the occurrence of the elements available in the list and print their counts

For example print as a=3, b =2 and c =1

  • kindly refer how to ask good questions and try again, note that you can edit your question: https://stackoverflow.com/help/how-to-ask – Peter Thomas Jun 20 '22 at 06:28
  • I hope solution from https://stackoverflow.com/questions/72685181/karate-trying-print-the-number-of-occurrence-of-element-in-the-list-dynamicall/72861094#72861094 might meets your requirement. – Srinivasu Kaki Jul 04 '22 at 19:12

1 Answers1

0

Just use JavaScript. The filter() operation is perfect for this:

* def data = ['a', 'c', 'b', 'c', 'c', 'd']
* def count = data.filter(x => x == 'c').length
* assert count == 3

Further reading: https://github.com/karatelabs/karate#json-transforms

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248