5
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 〜every〜

Last updated at Posted at 2023-01-05

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

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

お題
[1, 2, 3, 4, 5]の内容がすべて0より大きかったらtrue

Elixir

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

JavaScript

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

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

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