.DS_Store
# understand-javascript-arrays
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Plunker</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
// Array.prototype.slice();
// see CONSOLE!
var person = {
name: 'shane-osbourne'
};
var filters = {
'deslugify': x => x.replace('-', ' '),
'uppercase': x => x.toUpperCase()
};
var input = 'name | deslugify | uppercase'; // SHANE OSBOURNE
var sections = input.split('|').map(x => x.trim()); // [name, deslugify, uppercase]
var ref = person[sections[0]];
var output = sections
.slice(1)
.reduce((prev, next) => {
if (filters[next]) {
return filters[next].call(null, prev);
}
return prev;
}, ref);
console.log(output) || displayInPreview(output);
// display in plunker preview
function displayInPreview(string) {
var newDiv = document.createElement("div");
var newContent = document.createTextNode(string);
newDiv.appendChild(newContent);
document.body.appendChild(newDiv)
}