UNPKG

723 BJavaScriptView Raw
1export function test() {
2 const returnValue = [];
3 const reprs = [];
4
5 for (let i = 0; i < 10; i++) {
6 if (i % 2 === 0) {
7 returnValue.push(['odd', i]);
8 } else {
9 returnValue.push(['even', i]);
10 }
11
12 switch (i) {
13 case 0: {
14 const zeroStr = `zero=${i}`;
15 reprs.push(zeroStr);
16 break;
17 }
18 case 1: {
19 const oneStr = `one=${i}`;
20 reprs.push(oneStr);
21 break;
22 }
23 default:
24 // do nothing
25 }
26 }
27
28 // Ternary operator
29 return reprs.length === 0 ? 'zero' : reprs.length === 1 ? 'one' : 'other';
30}
31
32export function ternary() {
33 const booleanValue = true;
34 const falsyValue = null;
35 return falsyValue ? booleanValue : false;
36}