Rob
Rob

Reputation: 33

ramda array cleaning data to produce a unique array

I am looking to use Ramda to take some data - extract a key value from it - and reduce it so the array is unique

so in this case - create an array ["SONY_FINALIZING", "EXPIRE"]; -- as an extra - I would like to create other functionality to lowercase the values, add hyphens, camel case words.

trying to use this but can't seem to share a fiddle https://ramdajs.com/repl?v=0.26.1

const data2 = [
  {id: 38,
label: "ssss",
status: "SONY_FINALIZING",
region: "SIEA"},
  {id: 35,
label: "ghmjhmjhj",
status: "SONY_FINALIZING",
region: "SIEE"},
  {id: 32,
label: "gbfghfghfghg",
status: "EXPIRE",
region: "SIAE"}
]



pipe(
  groupBy(prop('id')), 
  map(pluck('status')),
  map(flatten),
  map(uniq),
)(data2)

Upvotes: 0

Views: 343

Answers (1)

Ori Drori
Ori Drori

Reputation: 191976

Create a function using R.pipe that uses R.pluck to get an array of status values, and then R.uniq to remove the duplicates:

const {pipe, pluck, uniq} = R;

const fn = pipe(pluck('status'), uniq);

const data2 = [{ id: 38, label: "ssss", status: "SONY_FINALIZING", region: "SIEA" }, { id: 35, label: "ghmjhmjhj", status: "SONY_FINALIZING", region: "SIEE" }, { id: 32, label: "gbfghfghfghg", status: "EXPIRE", region: "SIAE" } ];

const result = fn(data2);

console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.0/ramda.js" integrity="sha256-buL0byPvI/XRDFscnSc/e0q+sLA65O9y+rbF+0O/4FE=" crossorigin="anonymous"></script>

Upvotes: 1

Related Questions