Help us understand the problem. What is going on with this article?

新人プログラマ用練習問題「i18nやk8sを作ってみよう」

More than 1 year has passed since last update.

はじめに

  • 新人プログラマ用の練習問題を思いついたので載せます
  • 新人の方は是非解いてみてください
  • ベテランの方は新人教育などに使ってください

numeronym(ヌメロニム)とは

i18nやk8sのような数略語のこと
wikipedia
numeronym (数略語)のまとめ -- I18n、L10n、M17n、etc.

問題

「internationalization」を渡したら「i18n」を返す
「kubernetes」を渡したら「k8s」を返す
ようなget_numeronym関数を作成してください
言語は自由です
※なお、文字列以外が来るケースや1文字が来るケースなどは考慮しなくて良いものとする

回答例

js版
function get_numeronym(word){
  return word[0]+(word.length-2)+word[word.length-1];
}
or
function get_numeronym(word){
  return word.slice(0,1)+(word.length-2)+word.slice(-1)
}
ruby版
def get_numeronym word
  word.slice(0) + (word.size-2).to_s + word.slice(-1)
end
php版
<?php
function get_numeronym(string $word){
    return substr($word, 0, 1) . (strlen($word)-2) . substr($word, -1);
}
python版
def get_numeronym(word):
    return word[0] + str(len(word)-2) + word[-1]

おわりに

基本的に文字列操作しかしないのでプログラム入門の問題としては非常に取り組みやすそうだなと思って紹介しました
是非色んな解き方を試してみてください:smile:

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした