DEV Community

Discussion on: So many strings, so little time.

Collapse
 
pfacklam profile image
Paul Facklam

Thank you for sharing your experience with us, Megan. It's good that you got it working and I really like how you got there. 👏

But I also have to tell you that you didn't fulfill the whole mission. It does not return the Boolean false as mentioned above when there is no string inside the array. It returns undefined.

And this related to how you use the find function. Find works in this way that it returns the value (if found and depending on your comparison) or undefined (if not found). For finding a certain value you can pass in a function (aka callback). Inside this functon you can work with true (found the item. Stop and return it) and false (not the value I am looking for. Go on.) as return values. Means in your case: return typeof i === "string" would be enough. Next on your list: evaluating the return value for getFirstString => value or false. But I think you can handle it on your own. 👍