Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
for文禁止縛り in JS
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Nkowne63
March 28, 2019
Technology
780
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
for文禁止縛り in JS
for文を使わないで js を書くときに役立ちそうなtips
Nkowne63
March 28, 2019
More Decks by Nkowne63
See All by Nkowne63
暗号解読における量子計算の展望
neutron63zf
0
12
TypeScriptのコード生成をつらくしないために
neutron63zf
1
810
2020-11-05-side-effects-composition__1_.pdf
neutron63zf
1
460
vueで中規模以上のフロントエンドを組んでいて 役に立ったtips
neutron63zf
5
3.5k
20200128_nkowne63
neutron63zf
0
50
Vueで「見た目」「振る舞い」を分離してみよう
neutron63zf
0
630
20190523_nkowne63zf_1.pdf
neutron63zf
0
430
「つなぎこみ」を自動化する
neutron63zf
0
530
Other Decks in Technology
See All in Technology
OpenClawでAzure DevOpsのWiki更新を自動化する - クラウドAIだけでは届かない場所へ
yutakaosada
0
130
【ゲームメーカーズスクランブル2026】『Shadowverse: Worlds Beyond』UIとアニメーションで実現する最高のユーザー体験を叶えるプロトタイピング
cygames
PRO
1
700
ボードゲームの遊び相手をFoundation Modelsで作る / iOSDC Japan 2026
genda
0
220
The kernel report
ennael
PRO
1
130
20260929_AmazonGuardDutyの検出通知メールにAWS DevOpsAgentの調査結果を追加する
yhana
1
360
キャリアLT今日までそして明日から
kentapapa
1
120
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
3
21k
メルカリにおけるAI時代の高速プロトタイピング基盤「Arca」
ryotarai
18
13k
GitHub Agentic Workflows を触ってみる
htkym
2
860
LT:「このままでいいのかな?」から一歩踏み出した私のデータキャリア選択〜社会人3年目に上京を決意したリアル〜Snowflake女子会 vol.8
snowwmn0824
0
110
Argo CDとAtlantisで実現するインフラ管理のセルフサービス化──小規模SREチームで支えるプラットフォーム
cassius7
0
240
AWS App Runnerから Cloudflare Workersへ移行した話
ryota09
0
110
Featured
See All Featured
Making Projects Easy
brettharned
120
6.8k
Are puppies a ranking factor?
jonoalderson
2
4k
4 Signs Your Business is Dying
shpigford
187
23k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
540
The Cult of Friendly URLs
andyhume
79
7k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Bash Introduction
62gerente
615
220k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
So, you think you're a good person
axbom
PRO
2
2.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Crafting Experiences
bethany
1
360
Transcript
for文禁止縛り in JS
for文禁止縛りって? その名の通り、 for文を使わずに繰り返し処理を書こう! というもの。 用量・用法を守って適切に使いましょう ...
Step. 1 配列の加工 大体の繰り返しは、繰り返す対象の配列が存 在しているので結構使われる。 なかでも、一つ一つを加工する場合は多い。
Step. 1 配列の加工 こういう、「配列の個々の要素を加工する」系 の処理はmapで書ける。 加工する処理を関数として分離できた。
Step. 2 配列に関する繰り返し 配列を加工しないけど、「全要素に対してなん かしたい」ときもある。
Step. 2 配列に関する繰り返し そういうときはforEachを使うと書ける。 mapよりも自由度の高い処理が可能
Step. 3 前のループの結果が 必要 たまに、「前のループの結果」が必要な処理が ある。 右側のスクリプトは、配列の中のオブジェクト を全てマージする例。
Step. 3 前のループの結果が 必要 こういう場合こそ、「reduce」を使うことができ る。 サンプルは足し算なので、使いどころはないと 思われがちだが、実は汎用性が高い。 「今までの累計、今の要素の値」から、「今の 要素も含めた累計」を返す関数を使う。
Step. 4 オブジェクトの プロパティごとに処理 右側はプロパティの値を全部 1加算するスクリ プト。
Step. 4 オブジェクトの プロパティごとに処理 Object.entries関数を使うと、オブジェクトを [key, value]の配列に変換することができる。 Step. 3を使うともとのオブジェクトに戻せる。 賛否両論。
Step. 5 探索 while文やfor文で配列の要素を探索する場合 を考える(効率は悪いのでこんなことしないか もしれないが) 右のは、最初の偶数を探すプログラム。
Step. 5 探索 こういうのは、「find」という関数が用意されて いる。indexOfで探索する手法が一般的だ が、値だけ必要な場合はfindで充分である。 条件を満たす全ての値が欲しいときは filterを 使う。
Step. x その他 上のでできないこと • break(for文禁止縛りでもできないことはないがどれも黒魔術) • 任意回数ループ(メモリを食わずにやる方法を知りたい ...)