I am trying to reduce the execution time of the program I'm working on, and I want to find an easier way to find the index of a character with an integer value.
At the moment, my function keeps track of every character in the string and returns the index index of the first integer it finds. As an example, if I had a string JohnCena1237728394712(yes, this first line I was thinking about), the function should return 8, because the first integer that appears on line 1 is at index 8. It should be the first loop however, through each character before this find this index, and it is sometimes expensive.
If this helps in trying to find an easier way to do this, I can be sure that the function will always be in the format of [letters] "+" [numbers] ", so I just have to find the end of the (supposedly random) segment of letters so get what i want.
What I would like to do is use indexOf (), so I don’t have to use a loop, but I don’t know how to use a function without ten if statements (which, of course, will defeat the goal).
Is there a way to check multiple integers at once when using the indexOf () function or some other function?
source
share