3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

なおとさんの「コーディング面接した際の出題問題(Sort)」をbash で解いてみた

Posted at

※個人的なエッセイを多分に含みますので、その点はご了承ください:bow_tone1:

最近プライベートで@turmericN (なおと)さんと、とある開発プロジェクトをやっています。
その開発チームのSlack での一言…。

p1.png

おっ:open_mouth:

p2.png

問題はJavaScript ということでしたが、私はLinux 愛好家:sunglasses:。ということでbash でも書いてみました。


#!/bin/bash
data="pineapple,160
apple,80
watermelon,160
grape,160
melon,80
mango,170
banana,80
strawberry,170
peach,160
orange,170
kiwi,80
"

printSortedData() {
    sort -s -t',' -k2 -n < <(printf %s "$1")
}

printSortedData "$data"

# should print
# apple,80
# melon,80
# banana,80
# kiwi,80
# pineapple,160
# watermelon,160
# grape,160
# peach,160
# mango,170
# strawberry,170
# orange,170

@turmericN (なおと)さんの元記事はこちらになります。

JavaScriptのコーディング面接した際の出題問題(Sort)

bash にお強い方、もっとこうすれば良い等のコメント大歓迎です:bow_tone1:

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?