Skip to content

Instantly share code, notes, and snippets.

@vmlf01
Last active October 27, 2017 08:19
Show Gist options
  • Save vmlf01/29214971db53d9cb19e948fe6621f14d to your computer and use it in GitHub Desktop.
Save vmlf01/29214971db53d9cb19e948fe6621f14d to your computer and use it in GitHub Desktop.
TypeScript training - module 1 sample
const itemsList = [
"eggs",
"milk",
"donuts",
"butter",
"coca-cola",
];
function itemize(items: string[]): string[] {
return items
.map((item, index) => `${index + 1}. ${item.substring(0, 1).toUpperCase()}${item.substring(1)}`);
}
const itemsToBuy = itemize(itemsList);
itemsToBuy.forEach((item) => console.log(item)); // tslint:disable-line no-console
// forces tsc to consider this file as a "module", so it doesn't conflict with other global declarations
export { };
var itemsList = [
"eggs",
"milk",
"donuts",
"butter",
"coca-cola"
];
/**
* Converts items to Title-case and prefixed with item number
* @param {string[]} items
* @returns {string[]}
*/
function itemize(items) {
// TODO: Converts items to Title-case and prefixed with item number
return items;
}
var itemsToBuy = itemize(itemsList);
// EXPECTED:
// 1. Eggs
// 2. Milk
// 3. Donuts
// ...
itemsToBuy.forEach(item => console.log(item));
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"quotemark": [true, "single"],
"semicolon": [true, "always"],
"prefer-const": true,
"trailing-comma": [true, { "multiline": "always", "singleline": "never" }],
"no-consecutive-blank-lines": true,
"eofline": true,
"indent": [true, "spaces", 4]
},
"rulesDirectory": []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment