Last active
February 4, 2016 20:55
-
-
Save cavedave/8304548 to your computer and use it in GitHub Desktop.
node school functional javascript
This file contains 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
/* | |
uppercase everything | |
*/ | |
module.exports = function(input) { | |
return input.toString().toUpperCase(); | |
} | |
/* | |
make a higher order function | |
*/ | |
function repeat(operation, num) { | |
for(i=0;i<num;i++){ | |
operation(); | |
} | |
} | |
module.exports = repeat | |
/* | |
use map to double | |
*/ | |
function doubleAll(numbers) { | |
return numbers.map(double); | |
} | |
var double = function(single) { | |
return single *2; | |
} | |
module.exports = doubleAll | |
/* | |
array method chaining | |
*/ | |
module.exports = function getShortMessages(messages) { | |
return messages.filter(isBigEnough) | |
.map(simpler); | |
} | |
function isBigEnough(element) { | |
// console.log(element.message); | |
if(element.message.length< 50){ | |
return element.message; | |
} | |
} | |
function simpler(element){ | |
return element.message; | |
} | |
/* | |
every some | |
*/ | |
module.exports = function checkUsersValid(goodUsers) { | |
return function(submittedUsers) { | |
return submittedUsers.every(function(element){ | |
//console.log(element.id); | |
return (goodUsers.some( | |
function(user){ | |
//console.log(user.id); | |
return element.id === user.id; | |
} | |
)); | |
} | |
) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment