-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (75 loc) · 2.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
DeepDL translate color names to english names and convert to hex
formulate an answer e.g. person has COLOR eyes and wants to become a FUTUREJOB
COLOR eyes likes to eat / drink Dairy in the DIRECTION WIND.
*/
const utilities = require('./modules/util')
// Initializing hoisted variables
const DATASET = require('./tech-track-dataset.json')
const SAMPLE = require('./sample.json')
/*
Get all entries with specific question
Currently console logs instead of returning it
*/
const getAllValuesFromQuestion = (question) => {
const permutableData = Object.assign({}, DATASET)
return Object.entries(permutableData).forEach(([key, value]) => console.log(`${key}, ${utilities.toLowerCase(value[question])}`))
}
/**
* @title Get a specific form's question response back.
* @param {Number} key Which object you specifically want
* @param {String} value Question which you want the response from
* @returns
*/
const getSpecificDataValue = (key, value) => {
return SAMPLE[key][value]
}
/*
Function that works with promises to clean the data. It retrieves the data and unleashes a scrubbing chain.
Promise chain is based on the chain @roberrrt-s wrote.
Promise eventually returns a new person object with the properties eyeColour, diary and wind direction.
*/
const sanitizeData = () => {
return new Promise((resolve, reject) => {
const dataset = DATASET
resolve(dataset)
})
}
sanitizeData()
.then((data) => {
return data.map(object => {
Object.keys(object).forEach(key => {
object[key] = utilities.toLowerCase(object[key])
object[key] = utilities.removeSymbols(object[key])
object[key] = utilities.replaceEmptyValue(object[key])
})
return object
})
})
.then((data) => {
return data.map(object => {
const person = {
oogkleur: object['Wat is je oogkleur?'],
zuivel: object['Wat is je favoriete zuivelproduct?'],
wind: object['Wat is je favoriete windrichting?']
}
return person
})
})
.then(sanitizedData => {
console.log(sanitizedData)
/*
// Object in story format
return sanitizedData.map(obj => {
console.log(`persoon met oogkleur ${obj.oogkleur} vind zuivel product ${obj.zuivel} lekker in ${obj.wind} wind`)
})
*/
})
.catch(error => {
console.error(error)
})
.finally(() => {
console.log('%c sanitization is finished.', 'color:yellow; font-weight:bold;')
})
// console.log(utilities.replaceEmptyValue(getAllValuesFromQuestion('Wat is je oogkleur?')))
console.log(`American date "2021-02-09" to universal date: ${utilities.toLocalDateFormat(getSpecificDataValue(1, 'Wat is je favoriete datum?'))}`)