Write a function that outputs all the words ending in a "s", in a sentence sent to it as a parameter.

a function that outputs all the words ending in a "s", in a sentence sent to it as a parameter.

Done!!

No... Seriously. Why not try first, then get some feedback?

If you are in a computer science course, I hope you know what a function is. At that, you should know the parameter is what is passed into the function.

You will likely be returning an array of strings which, depending on the language you are using, can be as simple as a regex, quite ironically, as complex as a regex

^^ As he's posting in the PHP forum hopefully its PHP he's using lol ;)

<?php

function YourFunctionsName ($string)
{
    if (substr($string, -1) == ','))
    {
        echo $string;
    }
}

?>

You can use regex, but it would look like if (preg_match('/,$/', $string)) and this to me is a bit of an overkill

The purpose was to encourage him to try on his own, giving a place to start.

I admit, I answered on my phone and didn't think to look what forum I was in... But answering this kind of question by doing the work for him hardly teaches anything. :/

Also... I do not believe your solution is at all correct to answer his problem. You may want to reread his request.

I am not as polite as you two

Do your own bloody homework
die('lazy students');

commented: my sentiments exactly +15
Member Avatar for diafol

This is not "SO" nor are contributors here 'rent-a-dupe'. This forum is primarily a learning platform. While we all get carried away from time to time with providing "freebies", this should be avoided where possible as ryantroop correctly points out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.