10
3

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.

ElixirAdvent Calendar 2022

Day 17

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

Last updated at Posted at 2023-01-03

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

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

お題
[1, 2, 3, 4, 5]のリスト又は配列を2倍する

Elixir

x = [1, 2, 3, 4, 5]
y = Enum.map(x, fn x -> x * 2 end)
IO.inspect(x)
IO.inspect(y)

実行結果
[1, 2, 3, 4, 5]
[2, 4, 6, 8, 10]

JavaScript

x = [1, 2, 3, 4, 5]
y = x.map( (x) => x * 2)
console.log(x)
console.log(y)
実行結果
/usr/local/bin/node ./hoge.js
(5) [1, 2, 3, 4, 5]
(5) [2, 4, 6, 8, 10]

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

10
3
2

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
10
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?