| 
									
										
										
										
											2020-04-13 10:31:13 -07:00
										 |  |  | load("test-common.js"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 08:26:09 -05:00
										 |  |  | try { | 
					
						
							| 
									
										
										
										
											2020-04-13 14:08:27 +01:00
										 |  |  |     let getNumber = () => 42; | 
					
						
							|  |  |  |     assert(getNumber() === 42); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-05 18:05:50 -07:00
										 |  |  |     getNumber = () => 99; | 
					
						
							|  |  |  |     assert(getNumber() === 99); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 14:08:27 +01:00
										 |  |  |     let add = (a, b) => a + b; | 
					
						
							|  |  |  |     assert(add(2, 3) === 5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const addBlock = (a, b) => { | 
					
						
							|  |  |  |         let res = a + b; | 
					
						
							|  |  |  |         return res; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     assert(addBlock(5, 4) === 9); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const makeObject = (a, b) => ({ a, b }); | 
					
						
							|  |  |  |     const obj = makeObject(33, 44); | 
					
						
							|  |  |  |     assert(typeof obj === "object"); | 
					
						
							|  |  |  |     assert(obj.a === 33); | 
					
						
							|  |  |  |     assert(obj.b === 44); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let returnUndefined = () => { }; | 
					
						
							|  |  |  |     assert(typeof returnUndefined() === "undefined"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const makeArray = (a, b) => [a, b]; | 
					
						
							|  |  |  |     const array = makeArray("3", { foo: 4 }); | 
					
						
							|  |  |  |     assert(array[0] === "3"); | 
					
						
							|  |  |  |     assert(array[1].foo === 4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let square = x => x * x; | 
					
						
							|  |  |  |     assert(square(3) === 9); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let squareBlock = x => { | 
					
						
							|  |  |  |         return x * x; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     assert(squareBlock(4) === 16); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const message = (who => "Hello " + who)("friends!"); | 
					
						
							|  |  |  |     assert(message === "Hello friends!"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const sum = ((x, y, z) => x + y + z)(1, 2, 3); | 
					
						
							|  |  |  |     assert(sum === 6); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const product = ((x, y, z) => { | 
					
						
							|  |  |  |         let res = x * y * z; | 
					
						
							|  |  |  |         return res; | 
					
						
							|  |  |  |     })(5, 4, 2); | 
					
						
							|  |  |  |     assert(product === 40); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const half = (x => { | 
					
						
							|  |  |  |         return x / 2; | 
					
						
							|  |  |  |     })(10); | 
					
						
							|  |  |  |     assert(half === 5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     console.log("PASS"); | 
					
						
							| 
									
										
										
										
											2020-03-30 08:26:09 -05:00
										 |  |  | } catch { | 
					
						
							| 
									
										
										
										
											2020-04-13 14:08:27 +01:00
										 |  |  |     console.log("FAIL"); | 
					
						
							| 
									
										
										
										
											2020-03-30 08:26:09 -05:00
										 |  |  | } |