DEV Community

Discussion on: Daily Challenge #1 - String Peeler

Collapse
 
lessp profile image
Tom Ekander

ReasonML

let strip = text =>
  String.(
    length(text) > 2
      ? switch (sub(text, 1, length(text) - 2)) {
        | s => Some(s)
        | exception _ => None
        }
      : None
  );

strip("hello"); // Some("ell")
strip("ab"); // None
strip(""); // None