Last active
October 27, 2017 08:19
-
-
Save vmlf01/29214971db53d9cb19e948fe6621f14d to your computer and use it in GitHub Desktop.
TypeScript training - module 1 sample
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
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 { }; |
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
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)); |
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
Show hidden characters
{ | |
"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