Login  Register

Re: Can it do this way ?

Posted by Richard O'Keefe on Sep 02, 2020; 10:38am
URL: https://forum.world.st/Can-it-do-this-way-tp5121193p5121202.html

There is simply no point in "taking the first nine numbers out".
And there shouldn't BE a test for the string being empty, anywhere.
'' '-' '---' and so on should all be handled the same way.

Oh well, what stops you doing

   digits := aString select: [:each | each ~= $-].
   digits size = 10 ifFalse: [^false].
   lastDigit := digits la ost.
   digits := digits copyFrom: 1 to: 9.
   ( (lastDigit = $X or: [lastDigit isDigit]) and: [
     digits allSatisfy: #isDigit]
   ) ifFalse: [^false].

Now my code does not do this, but it is just 16 lines of code with
nothing that it would make sense to extract.

On Wed, 2 Sep 2020 at 22:24, Roelof Wobben <[hidden email]> wrote:
Yep, I know that isValidIsbn is the method that must output if a isbn is
valid or not.

What I want to do is take the first 9 characters out so I can convert
them to a array of numbers where I can do the calculation on.
And take out the last char so I can seperate test if that is a valid
char. So between the 0 and 9 or a X

I do not think I would have do all the checks in that only method
because it would be a very big method then.

but if I understand you well  also the test if a string is empty should
be called from the isValidIsbn method or even checked there.

Roelof