-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
36 lines (25 loc) · 1.36 KB
/
test.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
const phoneNumbersData = require("./index")
// console.log(phoneNumbersData.findOne('codigo', '291'))
// console.log(phoneNumbersData.filter('codigo', '291'))
// Obtener todos los prefijos de una provincia, ej: Buenos Aires
// const prefijosBuenosAires = phoneNumbersData.filter('provincia', 'Buenos Aires')
// console.log(phoneNumbersData.utils.groupBy('provincia', prefijosBuenosAires, (each) => each.codigo ))
const arrayOfPrefixes = ['343', '291', '11']
const filtered = []
arrayOfPrefixes.forEach(prefix => {
let filteredByCode = phoneNumbersData.filter('codigo', prefix)
if(filteredByCode.length) {
filtered.push(phoneNumbersData.utils.groupBy('codigo', filteredByCode, each => ({ localidad: each.localidad, provincia: each.provincia})))
}
});
const final = []
filtered.forEach((el) => {
const key = Object.keys(el)[0]
let orderedByProvince = phoneNumbersData.utils.groupBy('provincia', el[key], (each) => ({ localidad: each.localidad}))
final.push({ [key]: orderedByProvince })
})
// const abv = phoneNumbersData.utils.groupBy('codigo', filtered, (each) => (each))
console.log('Final', JSON.stringify(final, null, 2))
// const ultraGroupBy = phoneNumbersData.utils.groupBy('codigo', abv, ( each )=> each)
// console.log(phoneNumbersData.utils.groupBy('codigo', abv['Santa Fe'], each => each.localidad))
// console.log('result', ultraGroupBy)