Skip to content

Instantly share code, notes, and snippets.

@tfogo
Last active January 23, 2017 22:18
Show Gist options
  • Save tfogo/1426586a9d00ec95c5b1790500472d25 to your computer and use it in GitHub Desktop.
Save tfogo/1426586a9d00ec95c5b1790500472d25 to your computer and use it in GitHub Desktop.
function getPrimePhoneNumbers(isoCountry, areaCode) {
// ...
// Get the length of the country code so we know what to cut off from the number
let countryCodeLen = countries[isoCountry].code.length;
// assign the resolution of phonePromise to a variable
let primeNumberPromise = phonePromise.then(data => {
var verifiedPrimes = [];
data.forEach(twilioObject => {
twilioObject.available_phone_numbers.forEach(e => {
if (primality(e.phone_number.slice(countryCodeLen))
&& !verifiedPrimes.includes(e.phone_number.slice(countryCodeLen))) {
// Slice off the country code using the length calculated above
verifiedPrimes.push(e.phone_number.slice(countryCodeLen));
}
})
});
return verifiedPrimes;
});
return primeNumberPromise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment