From 0cdd731feeb0284d4b471cb9aa18b134b9cc5724 Mon Sep 17 00:00:00 2001 From: mdunisch Date: Mon, 10 Apr 2017 09:03:17 +0200 Subject: [PATCH] refactor for es6 --- README.md | 2 +- exercises/1_getting_started/exercise.js | 7 ++----- .../1_getting_started/solution/solution.js | 6 ++---- exercises/2_sort_me/exercise.js | 7 ++----- exercises/2_sort_me/solution/solution.js | 10 +++------ exercises/3_in_every_case/exercise.js | 7 ++----- .../3_in_every_case/solution/solution.js | 9 ++++---- exercises/4_everyone_is_min/exercise.js | 7 ++----- .../4_everyone_is_min/solution/solution.js | 12 +++++------ exercises/5_chain_mail/exercise.js | 7 ++----- exercises/5_chain_mail/solution/solution.js | 12 +++-------- exercises/6_count_the_comments/exercise.js | 7 ++----- .../6_count_the_comments/solution/solution.js | 6 ++---- exercises/7_give_me_an_overview/exercise.js | 7 ++----- .../solution/solution.js | 6 ++---- exercises/8_analyze/exercise.js | 7 ++----- exercises/8_analyze/solution/solution.js | 12 +++++------ exercises/9_start_templating/exercise.js | 7 ++----- .../9_start_templating/solution/solution.js | 8 +++---- lololodash.js | 21 +++++++------------ package.json | 3 +++ 21 files changed, 59 insertions(+), 111 deletions(-) diff --git a/README.md b/README.md index 9545491..417a601 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ lololodash ![alt tag](https://raw.github.com/mdunisch/lololodash/master/screen.png) ## Getting Started ## -1. First, install [nodejs](http://nodejs.org) version 0.10 or later. +1. First, install [nodejs](http://nodejs.org) version 4.0 or later. 2. The `nodejs` installation will also install `npm`, the [Node Package Manager](https://www.npmjs.org/). diff --git a/exercises/1_getting_started/exercise.js b/exercises/1_getting_started/exercise.js index a5f65a0..023a4f0 100644 --- a/exercises/1_getting_started/exercise.js +++ b/exercises/1_getting_started/exercise.js @@ -1,9 +1,6 @@ -'use strict'; +const verify = require("../../lib/verify.js"); -var verify = require("../../lib/verify.js"); -var _ = require("lodash"); - -var run = { +const run = { json: [ { id: 22, diff --git a/exercises/1_getting_started/solution/solution.js b/exercises/1_getting_started/solution/solution.js index 866204e..21e3e69 100644 --- a/exercises/1_getting_started/solution/solution.js +++ b/exercises/1_getting_started/solution/solution.js @@ -1,8 +1,6 @@ -'use strict'; +const _ = require("lodash"); -var _ = require("lodash"); - -var filterwhere = function (item) { +const filterwhere = function (item) { return _.filter(item, {active: true}); }; diff --git a/exercises/2_sort_me/exercise.js b/exercises/2_sort_me/exercise.js index baec918..7588a44 100644 --- a/exercises/2_sort_me/exercise.js +++ b/exercises/2_sort_me/exercise.js @@ -1,9 +1,6 @@ -'use strict'; +const verify = require("../../lib/verify.js"); -var verify = require("../../lib/verify.js"), - _ = require("lodash"); - -var run = { +const run = { json: [ { article: 2323, diff --git a/exercises/2_sort_me/solution/solution.js b/exercises/2_sort_me/solution/solution.js index 8b36bd4..cb22665 100644 --- a/exercises/2_sort_me/solution/solution.js +++ b/exercises/2_sort_me/solution/solution.js @@ -1,11 +1,7 @@ -'use strict'; +const _ = require("lodash"); -var _ = require("lodash"); - -var sorting = function (collection) { - return _.sortBy(collection, function (item) { - return -item.quantity; - }); +const sorting = function (collection) { + return _.sortBy(collection, item => -item.quantity); /* Also possible: return _.sortBy(collection,"quantity").reverse(); diff --git a/exercises/3_in_every_case/exercise.js b/exercises/3_in_every_case/exercise.js index 9a2ca52..d20e8aa 100644 --- a/exercises/3_in_every_case/exercise.js +++ b/exercises/3_in_every_case/exercise.js @@ -1,9 +1,6 @@ -'use strict'; +const verify = require("../../lib/verify.js"); -var verify = require("../../lib/verify.js"), - _ = require("lodash"); - -var run = { +const run = { json: { Hamburg: { population: 1.698 }, Strasbourg: { population: 0.272 }, diff --git a/exercises/3_in_every_case/solution/solution.js b/exercises/3_in_every_case/solution/solution.js index 248e1b0..300a6cf 100644 --- a/exercises/3_in_every_case/solution/solution.js +++ b/exercises/3_in_every_case/solution/solution.js @@ -1,8 +1,7 @@ -'use strict'; +const _ = require("lodash"); -var _ = require("lodash"); - -module.exports = function(collection) { +const inEveryCase = function(collection){ + // add a size attribute to the collection based on the item's population return _.forEach(collection, function(item) { if (item.population > 1) { @@ -14,3 +13,5 @@ module.exports = function(collection) { } }); }; + +module.exports = inEveryCase; diff --git a/exercises/4_everyone_is_min/exercise.js b/exercises/4_everyone_is_min/exercise.js index a7e8344..b17aafb 100644 --- a/exercises/4_everyone_is_min/exercise.js +++ b/exercises/4_everyone_is_min/exercise.js @@ -1,9 +1,6 @@ -'use strict'; +const verify = require("../../lib/verify.js"); -var verify = require("../../lib/verify.js"), - _ = require("lodash"); - -var run = { +const run = { json: { Hamburg: [14, 15, 16, 14, 18, 17, 20, 22, 21, 18, 19, 23], Munich: [16, 17, 19, 20, 21, 23, 22, 21, 20, 19, 24, 23], diff --git a/exercises/4_everyone_is_min/solution/solution.js b/exercises/4_everyone_is_min/solution/solution.js index abdf27b..0204d91 100644 --- a/exercises/4_everyone_is_min/solution/solution.js +++ b/exercises/4_everyone_is_min/solution/solution.js @@ -1,16 +1,14 @@ -'use strict'; - -var _ = require("lodash"); +const _ = require("lodash"); var tempsort = function (item) { + var result = { hot: [], warm: [] }; - - function check_temp (item) { - return item > 19; - } + + // If temp > 19 + const check_temp = (item) => item > 19; _.forEach(item, function (town, townname) { diff --git a/exercises/5_chain_mail/exercise.js b/exercises/5_chain_mail/exercise.js index 623ea6d..48996d8 100644 --- a/exercises/5_chain_mail/exercise.js +++ b/exercises/5_chain_mail/exercise.js @@ -1,9 +1,6 @@ -'use strict'; +const verify = require("../../lib/verify.js"); -var verify = require("../../lib/verify.js"); -var _ = require("lodash"); - -var run = { +const run = { json: [ 'Test', 'Hello', 'World', 'Node', 'JavaScript' ], diff --git a/exercises/5_chain_mail/solution/solution.js b/exercises/5_chain_mail/solution/solution.js index c0f45dc..d98c9e7 100644 --- a/exercises/5_chain_mail/solution/solution.js +++ b/exercises/5_chain_mail/solution/solution.js @@ -1,15 +1,9 @@ -'use strict'; - -var _ = require("lodash"); +const _ = require("lodash"); var wordsmodify = function (arr) { return _.chain(arr) - .map(function (item) { - return item + 'Chained'; - }) - .map(function (item) { - return item.toUpperCase(); - }) + .map(item => item + 'Chained') + .map(item => item.toUpperCase()) .sortBy() .value(); }; diff --git a/exercises/6_count_the_comments/exercise.js b/exercises/6_count_the_comments/exercise.js index cf3672d..c8b3ef8 100644 --- a/exercises/6_count_the_comments/exercise.js +++ b/exercises/6_count_the_comments/exercise.js @@ -1,9 +1,6 @@ -'use strict'; +const verify = require("../../lib/verify.js"); -var verify = require("../../lib/verify.js"), - _ = require("lodash"); - -var run = { +const run = { json: [ { username: "tim", comment: "when you have new workshoppers?" }, { username: "cat_lover", comment: "wtf? where are all the cats gone?" }, diff --git a/exercises/6_count_the_comments/solution/solution.js b/exercises/6_count_the_comments/solution/solution.js index 6f41166..88e4d49 100644 --- a/exercises/6_count_the_comments/solution/solution.js +++ b/exercises/6_count_the_comments/solution/solution.js @@ -1,8 +1,6 @@ -'use strict'; +const _ = require("lodash"); -var _ = require("lodash"); - -var commentcount = function (comments) { +const commentcount = function (comments) { var counted = []; diff --git a/exercises/7_give_me_an_overview/exercise.js b/exercises/7_give_me_an_overview/exercise.js index 63bedfe..0eaa384 100644 --- a/exercises/7_give_me_an_overview/exercise.js +++ b/exercises/7_give_me_an_overview/exercise.js @@ -1,9 +1,6 @@ -'use strict'; +const verify = require("../../lib/verify.js"); -var verify = require("../../lib/verify.js"), - _ = require("lodash"); - -var run = { +const run = { json: [ { diff --git a/exercises/7_give_me_an_overview/solution/solution.js b/exercises/7_give_me_an_overview/solution/solution.js index 3a72d98..af561eb 100644 --- a/exercises/7_give_me_an_overview/solution/solution.js +++ b/exercises/7_give_me_an_overview/solution/solution.js @@ -1,8 +1,6 @@ -'use strict'; +const _ = require("lodash"); -var _ = require("lodash"); - -var overview = function (orders) { +const overview = function (orders) { var overviewarray = [], total = 0; diff --git a/exercises/8_analyze/exercise.js b/exercises/8_analyze/exercise.js index 493c59f..c4642be 100644 --- a/exercises/8_analyze/exercise.js +++ b/exercises/8_analyze/exercise.js @@ -1,9 +1,6 @@ -'use strict'; +const verify = require("../../lib/verify.js"); -var verify = require("../../lib/verify.js"), - _ = require("lodash"); - -var run = { +const run = { json: [ { name: "mike", diff --git a/exercises/8_analyze/solution/solution.js b/exercises/8_analyze/solution/solution.js index 9bf4bd1..94cfffe 100644 --- a/exercises/8_analyze/solution/solution.js +++ b/exercises/8_analyze/solution/solution.js @@ -1,12 +1,10 @@ -'use strict'; +const _ = require("lodash"); -var _ = require("lodash"); +const analyze = function (item) { -var analyze = function (item) { - - var average, - underperform, - overperform; + let average; + let underperform; + let overperform; // Sort item = _.sortBy(item, "income"); diff --git a/exercises/9_start_templating/exercise.js b/exercises/9_start_templating/exercise.js index d194d74..dc01cab 100644 --- a/exercises/9_start_templating/exercise.js +++ b/exercises/9_start_templating/exercise.js @@ -1,9 +1,6 @@ -'use strict'; +const verify = require("../../lib/verify.js"); -var verify = require("../../lib/verify.js"), - _ = require("lodash"); - -var run = { +const run = { json: { name: "Tom", login: [ diff --git a/exercises/9_start_templating/solution/solution.js b/exercises/9_start_templating/solution/solution.js index ed9c026..1393d1f 100644 --- a/exercises/9_start_templating/solution/solution.js +++ b/exercises/9_start_templating/solution/solution.js @@ -1,10 +1,8 @@ -'use strict'; +const _ = require("lodash"); -var _ = require("lodash"); +const template = function (inputvar) { -var template = function (inputvar) { - - var mytemplate = "Hello <%= name %> (logins: <%= login.length %>)"; + let mytemplate = "Hello <%= name %> (logins: <%= login.length %>)"; return _.template(mytemplate)(inputvar); }; diff --git a/lololodash.js b/lololodash.js index 3f1c65f..bf350c3 100644 --- a/lololodash.js +++ b/lololodash.js @@ -1,20 +1,13 @@ #!/usr/bin/env node -'use strict'; +const workshopper = require('workshopper'); +const updateNotifier = require('update-notifier'); +const packageJson = require('./package.json'); -var workshopper = require('workshopper'), - path = require('path'), - updateNotifier = require('update-notifier'), - pkg = require('./package.json'); - -updateNotifier({pkg: pkg}).notify(); - -function fpath(f) { - return path.join(__dirname, f); -} +updateNotifier({pkg: packageJson}).notify(); workshopper({ - name : 'lololodash', - appDir : __dirname, - languages : ['en', 'fr', 'ko'] + name: 'lololodash', + appDir: __dirname, + languages: ['en', 'fr', 'ko'] }); diff --git a/package.json b/package.json index 654a55b..474441a 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ "type": "git", "url": "https://github.com/mdunisch/lololodash.git" }, + "engines" : { + "node" : ">=4.0.0" + }, "bin": "lololodash.js", "preferGlobal": true, "keywords": [