Created
January 20, 2023 07:19
-
-
Save ginpachiSensei/394e7d70854cbc689d133abec5aaeb84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let value = "12AB34";//given string | |
| let val1 = value.split("");//split string | |
| //filter out the character and keep numbers | |
| let val2 = val1.filter(c =>{ | |
| if (c >= '0' && c <= '9') { | |
| return c; | |
| } | |
| }); | |
| //sum all the numbers in array | |
| let sum = 0; | |
| val2.forEach(x => {sum += parseInt(x);}); | |
| console.log(sum); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment