Is_valid_name Tests

There should be another test for is_valid_name(str) where it guards against a false positive answer. It is discussed in the explanation video but there should be a test for it. In the following code, there is an early return that passes all the given tests but when given a name such as "“Robert DOWNEY JR” then it passes rather than fails.

def is_valid_name(str)
	nameComponents = str.split(" ")
  	if !fullName(nameComponents)
          return false
    else 
      nameComponents.each do |name|
        if isProperCased(name)
          return true
        else 
          return false
        end
      end
    end
  	return something
end
  
def fullName(parts)
  return parts.length > 1
end

def isProperCased(name)
  properCase = name.capitalize
  return name == properCase
end

puts is_valid_name("Kush Patel")       # => true
puts is_valid_name("ROBERT DOWNEY JR") # => false
puts is_valid_name("Robert DOWNEY JR") # => should be false but actually returns true

I think I just went over a similar issue. In your code you write

def isProperCased(name)
 propercase = name.capitalize
 return name == proper case
end

Issue is, when you put the object “Robert” this returns true. The method has completed its purpose and will move on. I’d say, it may be better to try and write this so even if the statement is true the first time, it will check the rest of the nameComponents.
Please feel free to let me know if I am wrong… just started coding too

try and write this so even if the statement is true the first time, it will check the rest of the nameComponents.

Correct, I mentioned in my post that there is an early return, which I didn’t catch because the code actually passed all the tests. One fix is just to check if the name component passed in IS NOT proper cased and to return false in that case otherwise continue checking the rest of the string array.

nameComponents.each do |name|
  if !isProperCased(name)
    return false
  end
end