Skip to main content

src/textx.gleam

import gleam/string
import gleam/list 

pub fn reverse(word: String) -> String {
  string.reverse(word)
}
  
pub fn is_palindrome(word: String) -> Bool {
  let cleaned = string.lowercase(word)
  cleaned == reverse(cleaned)
}

pub fn capitalize(word: String) -> String {
  case string.pop_grapheme(word) {
    Error(_) -> ""
    Ok(#(first, rest)) -> string.uppercase(first) <> string.lowercase(rest)
  }
}

pub fn word_count(text: String) -> Int {
  text
  |> string.split(on: " ")
  |> list.filter(fn(word) { word != "" })
  |> list.length
}