String in alphabetical order Ruby

I am new to Ruby. I have written a solution in Java

public boolean checkOrder(String input) {
        boolean x = false;
        for (int i = 0; i < input.length() - 1; i++) {
            if (input.charAt(i) < input.charAt(i + 1) || input.charAt(i) == input.charAt(i + 1)) {
                x = true;
            } else {
                return false;
            }
        }
        return x;

    }

I want to do the same in ruby how can I convert the same into ruby. Thanks.

Answers


def checkOrder(input)
  input.chars.sort == input.chars.to_a
end

Need Your Help

UIWebView URL from String without http://

iphone objective-c ios sdk

So I check if the string starts with "http://" using the code below, and then I want to add "http://" so that I'm able to open the page in UIWebView.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.