4
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 1 year has passed since last update.

Elixirから覚えるJavaScript 〜filter関数〜

Last updated at Posted at 2023-01-04

僕は普段はElixirを使ってます
必要になったのでJavaScriptの勉強をはじめました
題名はElixirから覚えるJavaScriptですが、逆もできるかも?

今日はfilterを見てみたいと思います

お題
[1, 2, 3, 4, 5]の中から[3, 4, 5]を抽出

Elixir

x = [1, 2, 3, 4, 5]
y = Enum.filter(x, fn x -> x > 2 end)
IO.inspect(x)
IO.inspect(y)
実行結果
[1, 2, 3, 4, 5]
[3, 4, 5]

JavaScript

x = [1, 2, 3, 4, 5]
y = x.filter((x) => x > 2)
console.log(x)
console.log(y)
実行結果
[ 1, 2, 3, 4, 5 ]
[ 3, 4, 5 ]

無事に同じ結果になりました

4
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
4
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?