Skip to content

Instantly share code, notes, and snippets.

@onejohi
Created December 15, 2020 08:13
Show Gist options
  • Save onejohi/7a9634ec2bd3bd3fd0b029eef979fbc0 to your computer and use it in GitHub Desktop.
Save onejohi/7a9634ec2bd3bd3fd0b029eef979fbc0 to your computer and use it in GitHub Desktop.
const arrayOfNumbers = ['BOB778','KEK7899','FOR4442','KIMP889'];
const numberValues = arrayOfNumbers.map(item => item.match(/\d+/)[0]);
const sumOfNumbers = numberValues.reduce((total, num) => Number(total) + Number(num));
// sumOfNumbers = 14008 [778 + 7899 + 4442 + 889]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment