Created
March 21, 2012 18:36
-
-
Save holtbp/2150923 to your computer and use it in GitHub Desktop.
Array Elements Triple and Join
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
// Given an array ["foo", "bar", "baz"], | |
// return ["foo foo foo", "bar bar bar", "baz baz baz"] | |
var arr = ["foo", "bar", "baz"]; | |
function triple(element) { | |
return [element, element, element].join(" "); | |
} | |
arr.forEach(function() { | |
arr.unshift(triple(arr.pop())); | |
}); | |
console.log(arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment