Skip to content

Commit

Permalink
feat: sort languages alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahgoldwastaken committed Oct 21, 2020
1 parent ab582a0 commit c2bda68
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"wrangle": "node dist"
},
"dependencies": {
"alphabet": "^1.0.0",
"dotenv": "^8.2.0",
"ramda": "^0.27.1"
},
Expand Down
7 changes: 7 additions & 0 deletions src/clean-up-practice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import data from './practice-data.json'
import { compose } from 'ramda'
import { upper } from 'alphabet'

/*
This is a data clean-up practice based on data from a questionnaire me and other students have filled in. The data is not publicly available, so if you want to run this code you need to supply your own data that's similar.
Expand Down Expand Up @@ -52,6 +53,11 @@ const shortenedValues = {
ENG: 'Engels',
}

const sortLanguagesAlphabetically = (answers: string[][]) =>
answers.map(item =>
item.sort((a, b) => (upper.indexOf(a[0]) > upper.indexOf(b[0]) ? 1 : -1))
)

/**
* Capitalises the first letter of the language and the first letter after a dash
* @param answers Array of language answers
Expand Down Expand Up @@ -105,6 +111,7 @@ const pickSpokenLanguages = (d: typeof data) =>
* Composition of all the functions above to pass the data into
*/
const cleanUpSpokenLanguages = compose(
sortLanguagesAlphabetically,
capitaliseLanguages,
filterLanguagesOnInvalidValues,
expandShortenedLanguages,
Expand Down
8 changes: 8 additions & 0 deletions src/type-defs/alphabet.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module 'alphabet' {
const alphabet: string[]

export default alphabet

export const upper: string[]
export const lower: string[]
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
dependencies:
ts-toolbelt "^6.3.3"

alphabet@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/alphabet/-/alphabet-1.0.0.tgz#0d8f81ca3f78355126d724d145487e1e4ef377c0"
integrity sha1-DY+Byj94NVEm1yTRRUh+Hk7zd8A=

dotenv@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
Expand Down

0 comments on commit c2bda68

Please sign in to comment.