回答編集履歴
2
質問の変更に合わせて追記
test
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
```js
|
6
|
-
|
7
|
-
|
8
6
|
|
9
7
|
let number = -10;
|
10
8
|
|
@@ -117,3 +115,29 @@
|
|
117
115
|
);
|
118
116
|
|
119
117
|
```
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
---
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
# 質問の変更に合わせて追記
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
```js
|
130
|
+
|
131
|
+
let number = -10;
|
132
|
+
|
133
|
+
const images = ["img01", "img02", "img03", "img04", "img05"];
|
134
|
+
|
135
|
+
while (number < 20)
|
136
|
+
|
137
|
+
console.log(number,
|
138
|
+
|
139
|
+
images[Math.abs((Math.abs(number++) + images.length - 1) % ((images.length - 1) * 2) - (images.length - 1))],
|
140
|
+
|
141
|
+
);
|
142
|
+
|
143
|
+
```
|
1
追記
test
CHANGED
@@ -91,3 +91,29 @@
|
|
91
91
|
|
92
92
|
|
93
93
|
```
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
---
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
# 追記
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
Math.sign を使って条件式を外してみましたが、かなり読みにくいコードになりました。
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
```js
|
110
|
+
|
111
|
+
while (number < 20)
|
112
|
+
|
113
|
+
console.log(number,
|
114
|
+
|
115
|
+
images[Math.abs((Math.abs(number + images.length * Math.sign(Math.sign(++number))) - 1) % ((images.length - 1) * 2) - (images.length - 1))],
|
116
|
+
|
117
|
+
);
|
118
|
+
|
119
|
+
```
|