-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmapData.js
More file actions
42 lines (34 loc) · 1.21 KB
/
mapData.js
File metadata and controls
42 lines (34 loc) · 1.21 KB
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
const sanitizedZipcodes = []
//finding the zipcode in json
function addToSanitizedZipCodes(zipcodes) {
sanitizedZipcodes.push(zipcodes)
}
function processJsonArray(jsonArray) {
for (const index in jsonArray) {
const jsonObj = jsonArray[index]
const buyerAddress = jsonObj.buyerAddress
if (buyerAddress && typeof buyerAddress === 'string') {
console.error(`buyerAddress at index ${index} is not a string.`)
//this is where it messes up
const buyerAddress = jsonData[0].buyerAddress
if (typeof buyerAddress !== 'string') {
console.error('buyerAddress is not a string.')
return
}
// Sanitize the buyerAddress string by removing non-digit characters
const sanitizedAddress = buyerAddress.replace(/[^0-9]/g, '')
// Loop through the sanitized string to find 5 consecutive numbers
let zipcodes = ''
for (let i = 0; i < sanitizedAddress.length; i++) {
zipcodes += sanitizedAddress[i]
if (zipcodes.length === 5) {
break // Stop when you find 5 consecutive numbers
}
}
if (zipcodes.length === 5) {
addToSanitizedZipCodes(zipcodes)
}
}
}
}
export { sanitizedZipcodes, processJsonArray }