String in alphabetical order Ruby -
i new ruby. have written solution in java
public boolean checkorder(string input) { boolean x = false; (int = 0; < 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 same in ruby how can convert same ruby. thanks.
def checkorder(input) input.chars.sort == input.chars.to_a end
Comments
Post a Comment