Skip to content

Instantly share code, notes, and snippets.

@TN1ck
Created June 1, 2016 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TN1ck/8bac540cd60b7a9da6402a03b1c6c920 to your computer and use it in GitHub Desktop.
Save TN1ck/8bac540cd60b7a9da6402a03b1c6c920 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<!-- put markup and other contents here -->
</body>
</html>
// write ES2015 code and import modules from npm
// and then press "Execute" to run your program
const _ = require('lodash');
const test = ['test1'];
const test2 = ['test1', 'test2'];
const test3 = ['test1', 'test2', 'test3'];
const humanizeList = (array) => {
if (array.length <= 1) {
return array.join('');
}
const interposeWith = _.fill(Array(array.length - 2), ', ').concat(' und ');
return _(array).zip(interposeWith).flatten().value().join('');
};
console.log(humanizeList(test));
console.log(humanizeList(test2));
console.log(humanizeList(test3));
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"lodash": "4.13.1"
}
}
'use strict';
// write ES2015 code and import modules from npm
// and then press "Execute" to run your program
var _ = require('lodash');
var test = ['test1'];
var test2 = ['test1', 'test2'];
var test3 = ['test1', 'test2', 'test3'];
var humanizeList = function humanizeList(array) {
if (array.length <= 1) {
return array.join('');
}
var interposeWith = _.fill(Array(array.length - 2), ', ').concat(' und ');
return _(array).zip(interposeWith).flatten().value().join('');
};
console.log(humanizeList(test));
console.log(humanizeList(test2));
console.log(humanizeList(test3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment