Skip to content

Instantly share code, notes, and snippets.

@rabestro
Created March 11, 2023 12:45
Show Gist options
  • Save rabestro/33ab571b868803fe011b405e179c9cb5 to your computer and use it in GitHub Desktop.
Save rabestro/33ab571b868803fe011b405e179c9cb5 to your computer and use it in GitHub Desktop.
The solution for exercise 'Anagram': https://exercism.org/tracks/jq/exercises/anagram
def word_key: ascii_downcase | explode | sort;
(.subject | length) as $size |
(.subject | ascii_downcase) as $subject |
(.subject | word_key) as $subject_key |
def is_candidate: length == $size and ascii_downcase != $subject;
def is_anagram: word_key == $subject_key;
[
.candidates[] |
select(is_candidate) |
select(is_anagram)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment