2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Write Higher Order Arrow Functions
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 Remember to use < a > **`Read-Search-Ask` **</ a >  if you get stuck. Try to pair program  and write your own code 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-27 13:39:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Problem explanation:
  
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								We need to compute and square values from the `realNumberArray`  and store them in the variable `squaredIntegers`  using the `map()` , `filter()` , and/or `reduce()`  functions.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								##  Hint: 1
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*    You will need to `filter()`  the `realNumberArray`  for positive integers (decimals are not integers). 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								>  _try to solve the problem now_
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								##  Hint: 2
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*    You will need to `map()`  the values from your `filter()`  function to the variable `squaredIntegers` . 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								>  _try to solve the problem now_
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								##  Hint: 3
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*    Remember the magic of chaining functions. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								>  _try to solve the problem now_
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-27 13:39:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Spoiler alert!
  
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								**Solution ahead!**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-27 13:39:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								##  Code solution:
  
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```javascript
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const squareList = (arr) => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "use strict";
							 
						 
					
						
							
								
									
										
										
										
											2019-03-29 09:36:58 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      const squaredIntegers = arr.filter((num) => num > 0 & &  num % parseInt(num) === 0).map((num) => Math.pow(num, 2));
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      return squaredIntegers;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // test your code
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const squaredIntegers = squareList(realNumberArray);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    console.log(squaredIntegers);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-12-27 13:39:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  [Run code at codepen.io ](https://codepen.io/dylantyates/pen/WyWoYJ ) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Code explanation:
  
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Uses the operator `filter()`  and `map()`  functions to square all positive integers in a given array.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-27 13:39:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Alternative code solution:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```javascript
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // change code below this line
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const squaredIntegers = arr.filter((param) => Number.isInteger(param) & &  param >= 0).map(x => x * x);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // change code above this line
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  [Run code at repl.it ](https://repl.it/@AdrianSkar/ES6-Write-higher-order-arrow-functions ) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Code explanation
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This does basically the same but uses the `isInteger()`  method to check the numbers.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-27 13:39:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Resources
  
						 
					
						
							
								
									
										
										
										
											2018-10-12 15:37:13 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-27 13:39:51 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  ["Array.prototype.map()" - *MDN JavaScript reference* ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map ) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  ["Array.prototype.filter()" - *MDN JavaScript reference* ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter ) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  ["Array.prototype.reduce()" - *MDN JavaScript reference* ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce ) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  ["Number.isInteger()" - *MDN JavaScript reference* ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger ) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  ["Math.pow()" - *MDN JavaScript reference* ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow )