satoru

satoru

I’m working on the “Bob” exercise on the Elixir Track in Exercism.

I am testing for uppercase letter with this simple check: c in ?A..?Z, but one of the test cases requires that Unicode uppercase letters be handled.

I’ve Googled a little bit and couldn’t found anything useful. An answer on Stackoverflow suggested to use regular expression on the string. I wonder if there’s anything as simple as Unicode.is_upper? in the standard library.

Showing Posts 1 to 10

egze

egze

Maybe you can compare if your letter is equal to String.upcase of the same letter. If yes - then you have the uppercased letter :slight_smile:

satoru

satoru OP

I also need to check if it’s a “letter” at all, if it’s not a letter then I don’t check if it’s upper case.

malaire

malaire

Perhaps check if Unicode.category/1 returns :Lu.

EDIT: Just noticed that there is also Unicode.uppercase?/1 which does this exact check.

LostKobrakai

LostKobrakai

I was about to suggest ex_unicode as well, but given the nature of this being an exercise I doubt they expect people to use an external dependency.

egze

egze

Just a hint, I don’t think you need to check every codepoint individually, but instead try to work with the whole string input and just the String module.

satoru

satoru OP

What should I import to use Unicode?

satoru

satoru OP

I have to check for 2 conditions:

  1. Contains at least one letter
  2. All letters in the string is upper case
malaire

malaire

Unicode is from ex_unicode package.

Alternatively if you want to stay with standard library, check out Regex character classes which include alpha and upper.

satoru

satoru OP

Thanks.

Dusty

Dusty

When I first solved Bob, I did so entirely with the Regex module. One of the comments my mentor made, was that, although Bob can be solved many ways, the intent of this exercise (on the Elixir track) is to get you familiar with the String module. I was encouraged to return to the String module, and solve the exercise without using any regexes at all. The solution I came up with turned out to be much more elegant than the regex solution, and indeed required only functions from String.

Here is a hint to get you started: Under what conditions would the uppercase version of a string be the same as the original? Are there other relationships like this you can leverage?

Where Next? Top

Trending in Chat/Questions Top

krisleech
Hey folks, I’ve been using Elixir for over a couple of years (phx, ecto, broadway, oban). For this kind of work you do not tend, in my e...
New
mhindujadheerajsudan
Hi, I’m Dheeraj Sudan from the UK. I’m a software developer and also run a business with my wife Meenu Hinduja. I’m interested in getting...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews