Created
February 19, 2015 06:16
-
-
Save electricjesus/179f33b9b433d39fcb25 to your computer and use it in GitHub Desktop.
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
/* Functional Programming 101 | |
1.) Create a function 'last' that has the following use cases: | |
- last("abc") // --> outputs "c" | |
- last(1,2,3,"D") // --> outputs "D" | |
- last([1,2,3,4]) // --> outputs 4 | |
2.) Create a function named 'insertUnique' that accepts any object and ensures all objects in the resulting / current array is unique. | |
var myarray = []; | |
var myArray = insertUnique("a"); // results to myArray equals to ["a"] | |
myArray = insertUnique("a"); // results to myArray still equals to ["a"] | |
myArray = insertUnique({"a": 2}); // results to myArray now equals to ["a", {a: 2}] | |
BONUS | |
POINTS: turn insertUnique into a prototyped function. e.g.: | |
var myArray = []; | |
myArray.insertUnique("a"); // results to myArray equals to ["a"] | |
myArray.insertUnique("a"); // results to myArray still equals to ["a"] | |
myArray.insertUnique({"a": 2}); // results to myArray now equals to ["a", {a: 2}] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment