любой-язык – Code golf – sort string characters alphabetically


Task: write a function (method) that will take a string and return it sorted alphabetically, ignoring case.

  • For example, if you pass сТрока then it should return акорсТ .

  • The string passed to your function can be in both English and Russian, but not a combination of both. Moreover, the lines with the letter Y should also be sorted correctly .

    apHchiEmaYo -> aaEEImpHh

  • It is assumed that only a string of letters will be transmitted and nothing more (no numbers, no punctuation marks, nothing but letters)

Conditions: Participants can answer in different languages ​​by posting such solutions in different answers. The winner will be the one who writes it in fewer characters, the structure of the answer is the language, in brackets the number of characters, the code itself, a link to the check.

The winner will get 500 reputation, let's go! The results will be held in 3 days (the status of the competition will open, I will mark the winner's answer as correct)

Please indicate the number of characters in your answer to make it easier to identify the winner.

function getAnswers(questionId, answer_filter, page) {
  return jQuery.ajax({
    url: '//api.stackexchange.com/2.2/questions/' + questionId + '/answers?page=' + page + '&pagesize=100&order=desc&sort=activity&site=ru.stackoverflow&filter=' + answer_filter,
    method: "get",
    dataType: "jsonp",
    crossDomain: true
  }).then(function(data) {
    if (data.has_more) {

      return getAnswers(questionId, answer_filter, page + 1).then(function(d) {
        return data.items.concat(d.items);
    return data.items;

function getAuthorName(e) {
  return e.owner.display_name

function process(items) {

  return items.map(function(item) {
    var matched = item.body.match(/(\d+)[^\d]*?<\/h/);
    if (matched) {
      return {
        count: +matched[1],
        link: item.share_link,
        author: getAuthorName(item)

    } else {
      return {
        count: 'N/A',
        link: item.share_link,
        author: getAuthorName(item)

function sort(items) {
  return items.sort(function(a, b) {
    if (a.count == 'N/A') return 1;
    if (b.count == 'N/A') return -1;
    return a.count - b.count;

function fillTemplate(sortedItems) {
  $('#leadership').append(sortedItems.map(function(item, index) {
    return $('<tr>').append($('<td>').html(index + 1))
      .append($('<td>').append($('<a>').attr('href', item.link).text('Link')));
  return sortedItems;

var QUESTION_ID = 671346,
  ANSWER_FILTER = "!4*SyY(4Kifo3Mz*lT",
  startPage = 1;
getAnswers(QUESTION_ID, ANSWER_FILTER, startPage)
#leadership {
  border-collapse: collapse;
#leadership td,
#leadership th {
  padding: 5px;
#leadership th,
td:nth-child(3) {
  text-align: center;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Таблица лидеров</h1>
<table id="leadership">
    <th>Количество символов</th>


Python (43)

f=lambda s:''.join(sorted(s,key=str.lower))


Scroll to Top