-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: do data cleanup practice on language data
- Loading branch information
1 parent
694ec08
commit dd4c974
Showing
3 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
node_modules/ | ||
dist/ | ||
.cache/ | ||
.env | ||
.env | ||
*.csv | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import data from './practice-data.json' | ||
import { compose } from 'ramda' | ||
|
||
const validValues = [ | ||
'nederlands', | ||
'engels', | ||
'duits', | ||
'spaans', | ||
'frans', | ||
'tessels', | ||
'berbers', | ||
'marokkaans-arabisch', | ||
'koreaans', | ||
'cantonees', | ||
'ghanees', | ||
'fries', | ||
'kroatisch', | ||
'amerikaans', | ||
'zweeds', | ||
'pools', | ||
'tamil', | ||
'papiaments', | ||
'indonesisch', | ||
'gebarentaal', | ||
'indisch', | ||
'arabisch', | ||
'chinees', | ||
'html', | ||
'scss', | ||
'javascript', | ||
'jquery', | ||
'php', | ||
'alles', | ||
] | ||
|
||
const shortenedValues = { | ||
NL: 'Nederlands', | ||
EN: 'Engels', | ||
ENG: 'Engels', | ||
} | ||
|
||
const filterValueOnValidValues = (lang: string) => | ||
lang.length && | ||
Number.isNaN(Number(lang)) && | ||
validValues.includes(lang.toLowerCase()) | ||
|
||
const capitaliseLanguages = (answers: string[][]) => | ||
answers.map(item => item.map(lang => lang[0].toUpperCase() + lang.slice(1))) | ||
|
||
const filterLanguagesOnInvalidValues = (answers: string[][]) => | ||
answers.map(item => item.filter(filterValueOnValidValues)) | ||
|
||
const expandShortenedLanguages = (answers: string[][]) => | ||
answers.map(item => item.map(lang => (shortenedValues as any)[lang] || lang)) | ||
|
||
const splitLanguageString = (answers: string[]) => | ||
answers.map(val => val.slice().split(/;|,|\.|\s/)) | ||
|
||
const pickSpokenLanguages = (d: typeof data) => | ||
d.map(item => item.gesprokenTalen) | ||
|
||
const cleanUpSpokenLanguages = compose( | ||
capitaliseLanguages, | ||
filterLanguagesOnInvalidValues, | ||
expandShortenedLanguages, | ||
splitLanguageString, | ||
pickSpokenLanguages | ||
) | ||
|
||
console.log(cleanUpSpokenLanguages(data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters