Skip to content

Commit

Permalink
fix(hospitals): fix duplicate items (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
satyawikananda committed Oct 6, 2021
1 parent a6fa331 commit 0fa1628
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/scrape/hospitals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import type {
ResponseHopitalsList,
} from "~/types"

const removeDuplicateItems = (arr: Array<HospitalsList>) => {
const setValue = new Set()

return arr.filter((data) => {
const isInSet = setValue.has(data.id)
setValue.add(data.id)
return !isInSet
})
}

export const getHospitalList = async ({
type,
provinceid,
Expand All @@ -17,7 +27,7 @@ export const getHospitalList = async ({
`rumah_sakit?jenis=${type}&propinsi=${provinceid}&kabkota=${cityid}`,
)
const RE_NUMBER = /\d/
const hospitals: Array<HospitalsList> = []
let hospitals: Array<HospitalsList> = []

$(".row > .cardRS").each((_, el) => {
const beds: Array<BedsList> = []
Expand Down Expand Up @@ -93,10 +103,9 @@ export const getHospitalList = async ({
info
})
}

})
return {
status,
hospitals: hospitals,
hospitals: removeDuplicateItems(hospitals),
}
}

1 comment on commit 0fa1628

@vercel
Copy link

@vercel vercel bot commented on 0fa1628 Oct 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.