Last active
December 27, 2015 19:15
-
-
Save mmloveaa/771b2d3415d054f5ecb9 to your computer and use it in GitHub Desktop.
Solutions using .reduce() .map() .filter() .sort()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 12/21/2015 | |
// .reduce() method | |
function product(array){ | |
var answer=array.reduce(function(a,b){ | |
return a*b | |
}) | |
return answer | |
} | |
product([3,5,7,9,12]) | |
--------------------------------------- | |
// .map() method | |
function square(array){ | |
var array1=array.map(function(element){ | |
return element*element | |
}) | |
return array1; | |
} | |
square([1,3,5,7,9]) | |
-------------------------------------- | |
// .filter() method | |
var array1=[]; | |
function odd(array){ | |
array1=array.filter(function(element){ | |
return element%2==1 | |
}) | |
return array1; | |
} | |
odd([1,4,6,3,5,7,90]) | |
--------------------------------------------- | |
//.sort() method | |
var array2=[]; | |
function beer(array){ | |
array2=array.sort() | |
return array2 | |
} | |
beer(["g","d","r","h","b","m","a"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment