I have an array of phone numbers, say:
var phoneNums = [
8881749281,
8881533241,
9198421881,
...,
]
Its a much larger list than that (roughly 1,300 entries) but for simplicity, we will just use that.
The array is already in numerical order, but, I want to sort this array into many different arrays based on the area code.
So the logic would be something like this:
for loop
if first 3 numbers of this entry != first 3 numbers of the next entry
array.splice
I've just never had to do something like this using a regular expression before, so I dont really know where to begin.
I know the regular expression to get the first 3 numbers:
const patt = new RegExp('^\\d{3}')
And doing something like this: var newArr = nums.filter(x => patt)
for (var i = 0; i < newArr.length; i++)
console.log(newArr[i])
Is just giving me a list of all the full numbers, which isn't necessarily wrong, but I want it to just be the first 3 numbers.