From 5708dceb010aa9b272cbdc0529d762df1139929d Mon Sep 17 00:00:00 2001 From: Learner Date: Mon, 13 Feb 2017 14:56:15 -0800 Subject: [PATCH 01/12] created express app --- .gitignore | 1 + app.js | 46 ++++++++++++++++++ bin/www | 90 ++++++++++++++++++++++++++++++++++++ package.json | 17 +++++++ public/stylesheets/style.css | 8 ++++ routes/index.js | 9 ++++ routes/users.js | 9 ++++ views/error.pug | 6 +++ views/index.pug | 5 ++ views/layout.pug | 7 +++ 10 files changed, 198 insertions(+) create mode 100644 .gitignore create mode 100644 app.js create mode 100755 bin/www create mode 100644 package.json create mode 100644 public/stylesheets/style.css create mode 100644 routes/index.js create mode 100644 routes/users.js create mode 100644 views/error.pug create mode 100644 views/index.pug create mode 100644 views/layout.pug diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/app.js b/app.js new file mode 100644 index 0000000..e421c6d --- /dev/null +++ b/app.js @@ -0,0 +1,46 @@ +var express = require('express'); +var path = require('path'); +var favicon = require('serve-favicon'); +var logger = require('morgan'); +var cookieParser = require('cookie-parser'); +var bodyParser = require('body-parser'); + +var index = require('./routes/index'); +var users = require('./routes/users'); + +var app = express(); + +// view engine setup +app.set('views', path.join(__dirname, 'views')); +app.set('view engine', 'pug'); + +// uncomment after placing your favicon in /public +//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); +app.use(logger('dev')); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: false })); +app.use(cookieParser()); +app.use(express.static(path.join(__dirname, 'public'))); + +app.use('/', index); +app.use('/users', users); + +// catch 404 and forward to error handler +app.use(function(req, res, next) { + var err = new Error('Not Found'); + err.status = 404; + next(err); +}); + +// error handler +app.use(function(err, req, res, next) { + // set locals, only providing error in development + res.locals.message = err.message; + res.locals.error = req.app.get('env') === 'development' ? err : {}; + + // render the error page + res.status(err.status || 500); + res.render('error'); +}); + +module.exports = app; diff --git a/bin/www b/bin/www new file mode 100755 index 0000000..792fcd9 --- /dev/null +++ b/bin/www @@ -0,0 +1,90 @@ +#!/usr/bin/env node + +/** + * Module dependencies. + */ + +var app = require('../app'); +var debug = require('debug')('npm-modules:server'); +var http = require('http'); + +/** + * Get port from environment and store in Express. + */ + +var port = normalizePort(process.env.PORT || '3000'); +app.set('port', port); + +/** + * Create HTTP server. + */ + +var server = http.createServer(app); + +/** + * Listen on provided port, on all network interfaces. + */ + +server.listen(port); +server.on('error', onError); +server.on('listening', onListening); + +/** + * Normalize a port into a number, string, or false. + */ + +function normalizePort(val) { + var port = parseInt(val, 10); + + if (isNaN(port)) { + // named pipe + return val; + } + + if (port >= 0) { + // port number + return port; + } + + return false; +} + +/** + * Event listener for HTTP server "error" event. + */ + +function onError(error) { + if (error.syscall !== 'listen') { + throw error; + } + + var bind = typeof port === 'string' + ? 'Pipe ' + port + : 'Port ' + port; + + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': + console.error(bind + ' requires elevated privileges'); + process.exit(1); + break; + case 'EADDRINUSE': + console.error(bind + ' is already in use'); + process.exit(1); + break; + default: + throw error; + } +} + +/** + * Event listener for HTTP server "listening" event. + */ + +function onListening() { + var addr = server.address(); + var bind = typeof addr === 'string' + ? 'pipe ' + addr + : 'port ' + addr.port; + debug('Listening on ' + bind); +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ecfc861 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "npm-modules", + "version": "0.0.0", + "private": true, + "scripts": { + "start": "node ./bin/www" + }, + "dependencies": { + "body-parser": "~1.16.0", + "cookie-parser": "~1.4.3", + "debug": "~2.6.0", + "express": "~4.14.1", + "pug": "latest", + "morgan": "~1.7.0", + "serve-favicon": "~2.3.2" + } +} diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css new file mode 100644 index 0000000..9453385 --- /dev/null +++ b/public/stylesheets/style.css @@ -0,0 +1,8 @@ +body { + padding: 50px; + font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; +} + +a { + color: #00B7FF; +} diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..ecca96a --- /dev/null +++ b/routes/index.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.render('index', { title: 'Express' }); +}); + +module.exports = router; diff --git a/routes/users.js b/routes/users.js new file mode 100644 index 0000000..623e430 --- /dev/null +++ b/routes/users.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET users listing. */ +router.get('/', function(req, res, next) { + res.send('respond with a resource'); +}); + +module.exports = router; diff --git a/views/error.pug b/views/error.pug new file mode 100644 index 0000000..51ec12c --- /dev/null +++ b/views/error.pug @@ -0,0 +1,6 @@ +extends layout + +block content + h1= message + h2= error.status + pre #{error.stack} diff --git a/views/index.pug b/views/index.pug new file mode 100644 index 0000000..3d63b9a --- /dev/null +++ b/views/index.pug @@ -0,0 +1,5 @@ +extends layout + +block content + h1= title + p Welcome to #{title} diff --git a/views/layout.pug b/views/layout.pug new file mode 100644 index 0000000..15af079 --- /dev/null +++ b/views/layout.pug @@ -0,0 +1,7 @@ +doctype html +html + head + title= title + link(rel='stylesheet', href='/stylesheets/style.css') + body + block content From d2c256047cae854006e435e7a682d44ed0e93fcf Mon Sep 17 00:00:00 2001 From: Learner Date: Mon, 13 Feb 2017 15:41:17 -0800 Subject: [PATCH 02/12] implemented add function and test for function --- package.json | 7 +++++-- routes/index.js | 2 +- spec/add.js | 3 +++ test/add.test.js | 8 ++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 spec/add.js create mode 100644 test/add.test.js diff --git a/package.json b/package.json index ecfc861..79fef7c 100644 --- a/package.json +++ b/package.json @@ -3,15 +3,18 @@ "version": "0.0.0", "private": true, "scripts": { - "start": "node ./bin/www" + "start": "node ./bin/www", + "test": "mocha" }, "dependencies": { "body-parser": "~1.16.0", + "chai": "^3.5.0", "cookie-parser": "~1.4.3", "debug": "~2.6.0", "express": "~4.14.1", - "pug": "latest", + "mocha": "^3.2.0", "morgan": "~1.7.0", + "pug": "latest", "serve-favicon": "~2.3.2" } } diff --git a/routes/index.js b/routes/index.js index ecca96a..6d46aa7 100644 --- a/routes/index.js +++ b/routes/index.js @@ -3,7 +3,7 @@ var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { - res.render('index', { title: 'Express' }); + res.render('index', { title: 'NPM Modules for JS' }); }); module.exports = router; diff --git a/spec/add.js b/spec/add.js new file mode 100644 index 0000000..9d6c8e2 --- /dev/null +++ b/spec/add.js @@ -0,0 +1,3 @@ +module.exports = function (num1,num2){ + return num1 + num2 +} diff --git a/test/add.test.js b/test/add.test.js new file mode 100644 index 0000000..fe9039d --- /dev/null +++ b/test/add.test.js @@ -0,0 +1,8 @@ +var {expect} = require("chai") +var add = require("../spec/add") + +describe("add", function() { + it("should add two numbers", function(){ + expect(add( 1 , 2 )).to.eql(3) + }) +}) From e6edb085fbe9705c7090d3ea21fddecfe96ae1d3 Mon Sep 17 00:00:00 2001 From: Learner Date: Mon, 13 Feb 2017 16:35:44 -0800 Subject: [PATCH 03/12] add subtraction --- spec/subtract.js | 0 test/test.subtract.js | 8 ++++++++ 2 files changed, 8 insertions(+) create mode 100644 spec/subtract.js create mode 100644 test/test.subtract.js diff --git a/spec/subtract.js b/spec/subtract.js new file mode 100644 index 0000000..e69de29 diff --git a/test/test.subtract.js b/test/test.subtract.js new file mode 100644 index 0000000..7b585c7 --- /dev/null +++ b/test/test.subtract.js @@ -0,0 +1,8 @@ +var {expect} = require("chai") +var subtract = require("../spec/subtract") + +describe("subtract", function() { + it("should subtract Num2 from Num1", function(){ + expect(subtract( 1 , 2 )).to.eql(3) + }) +}) From 865a986958aecdd85a5ab41254bfe1e999409722 Mon Sep 17 00:00:00 2001 From: rogercamps Date: Mon, 13 Feb 2017 17:02:07 -0800 Subject: [PATCH 04/12] modify subtract test --- test/subtract.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/subtract.test.js diff --git a/test/subtract.test.js b/test/subtract.test.js new file mode 100644 index 0000000..7307f59 --- /dev/null +++ b/test/subtract.test.js @@ -0,0 +1,8 @@ +var {expect} = require("chai") +var subtract = require("../spec/subtract") + +describe("subtract", function() { + it("should subtract Num2 from Num1", function(){ + expect(subtract( 1 , 2 )).to.eql(-1) + }) +}) From cd43827e6aeb8be4ab29d9f291f184d037e8c6e7 Mon Sep 17 00:00:00 2001 From: Learner Date: Mon, 13 Feb 2017 17:20:30 -0800 Subject: [PATCH 05/12] multiplies Num1 by Num2 --- spec/multiply.js | 3 +++ spec/subtract.js | 3 +++ test/multiply.test.js | 8 ++++++++ test/{test.subtract.js => subtract.test.js} | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 spec/multiply.js create mode 100644 test/multiply.test.js rename test/{test.subtract.js => subtract.test.js} (80%) diff --git a/spec/multiply.js b/spec/multiply.js new file mode 100644 index 0000000..d1624e2 --- /dev/null +++ b/spec/multiply.js @@ -0,0 +1,3 @@ +module.exports = function (num1,num2){ + return (num1 * num2) +} diff --git a/spec/subtract.js b/spec/subtract.js index e69de29..e442ec2 100644 --- a/spec/subtract.js +++ b/spec/subtract.js @@ -0,0 +1,3 @@ +module.exports = function (num1,num2){ + return num1 - num2 +} diff --git a/test/multiply.test.js b/test/multiply.test.js new file mode 100644 index 0000000..1d9d9b2 --- /dev/null +++ b/test/multiply.test.js @@ -0,0 +1,8 @@ +var {expect} = require("chai") +var multiply = require("../spec/multiply") + +describe("multiply", function() { + it("should multiply num1 by num2", function() { + expect(multiply( 1 , 2 )).to.eql(2) + }) +}) diff --git a/test/test.subtract.js b/test/subtract.test.js similarity index 80% rename from test/test.subtract.js rename to test/subtract.test.js index 7b585c7..7307f59 100644 --- a/test/test.subtract.js +++ b/test/subtract.test.js @@ -3,6 +3,6 @@ var subtract = require("../spec/subtract") describe("subtract", function() { it("should subtract Num2 from Num1", function(){ - expect(subtract( 1 , 2 )).to.eql(3) + expect(subtract( 1 , 2 )).to.eql(-1) }) }) From 158701f8a804e545e504777b5bd07809b2a7bc2e Mon Sep 17 00:00:00 2001 From: Learner Date: Tue, 14 Feb 2017 08:53:37 -0800 Subject: [PATCH 06/12] Adds division equation and test using lodash.divide --- spec/add.js | 2 +- spec/divide.js | 4 ++++ spec/subtract.js | 2 +- test/divide.test.js | 8 ++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 spec/divide.js create mode 100644 test/divide.test.js diff --git a/spec/add.js b/spec/add.js index 9d6c8e2..704c068 100644 --- a/spec/add.js +++ b/spec/add.js @@ -1,3 +1,3 @@ module.exports = function (num1,num2){ - return num1 + num2 + return (num1 + num2) } diff --git a/spec/divide.js b/spec/divide.js new file mode 100644 index 0000000..a388205 --- /dev/null +++ b/spec/divide.js @@ -0,0 +1,4 @@ +module.exports = _.divide(6, 4); +// => 1.5){ + return ('lodash.divide') +} diff --git a/spec/subtract.js b/spec/subtract.js index e442ec2..e632fdc 100644 --- a/spec/subtract.js +++ b/spec/subtract.js @@ -1,3 +1,3 @@ module.exports = function (num1,num2){ - return num1 - num2 + return (num1 - num2) } diff --git a/test/divide.test.js b/test/divide.test.js new file mode 100644 index 0000000..a14fc3d --- /dev/null +++ b/test/divide.test.js @@ -0,0 +1,8 @@ +var {expect} = require("chai") +var divide = require('lodash.divide') + +describe("divide", function() { + it("should divide num1 by num2", function() { + expect(divide( 1 , 2 )).to.eql(.5) + }) +}) From 2aac6838e941aa8059bc68ca703f2638e7abf9db Mon Sep 17 00:00:00 2001 From: rogercamps Date: Tue, 14 Feb 2017 11:32:35 -0800 Subject: [PATCH 07/12] complete min, ceil and mdofied divide --- spec/ceil.js | 3 +++ spec/divide.js | 6 +++--- spec/min.js | 7 +++++++ test/ceil.test.js | 8 ++++++++ test/divide.test.js | 2 +- test/min.test.js | 8 ++++++++ 6 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 spec/ceil.js create mode 100644 spec/min.js create mode 100644 test/ceil.test.js create mode 100644 test/min.test.js diff --git a/spec/ceil.js b/spec/ceil.js new file mode 100644 index 0000000..5f4110b --- /dev/null +++ b/spec/ceil.js @@ -0,0 +1,3 @@ +module.exports = function (num1){ + return Math.ceil(num1) +} diff --git a/spec/divide.js b/spec/divide.js index a388205..f80b510 100644 --- a/spec/divide.js +++ b/spec/divide.js @@ -1,4 +1,4 @@ -module.exports = _.divide(6, 4); -// => 1.5){ - return ('lodash.divide') +module.exports = function(num1 , num2){ + // 1.5){ + return (num1 / num2) } diff --git a/spec/min.js b/spec/min.js new file mode 100644 index 0000000..51a0b90 --- /dev/null +++ b/spec/min.js @@ -0,0 +1,7 @@ +module.exports = function min( inputArray ) { + if(Array.isArray(inputArray)){ + return Math.min.apply(null, inputArray) + } else { + return + } +} diff --git a/test/ceil.test.js b/test/ceil.test.js new file mode 100644 index 0000000..83ed706 --- /dev/null +++ b/test/ceil.test.js @@ -0,0 +1,8 @@ +var {expect} = require("chai") +var ceil = require('../spec/ceil') + +describe("ceil", function() { + it("should compute number rounded up to precision", function() { + expect(ceil(3.2)).to.eql(4) + }) +}) diff --git a/test/divide.test.js b/test/divide.test.js index a14fc3d..4cb89b2 100644 --- a/test/divide.test.js +++ b/test/divide.test.js @@ -1,5 +1,5 @@ var {expect} = require("chai") -var divide = require('lodash.divide') +var divide = require('../spec/divide') describe("divide", function() { it("should divide num1 by num2", function() { diff --git a/test/min.test.js b/test/min.test.js new file mode 100644 index 0000000..c5b4591 --- /dev/null +++ b/test/min.test.js @@ -0,0 +1,8 @@ +var {expect} = require("chai") +var min = require('../spec/min') + +describe("min", function() { + it("should display the lowest number in an array", function() { + expect(min([4, 1, 2, 3])).to.eql(1) + }) +}) From f5aed5f72bc4dbe9a7e1f1f4869cfa4bb645b50b Mon Sep 17 00:00:00 2001 From: Learner Date: Wed, 15 Feb 2017 17:33:57 -0800 Subject: [PATCH 08/12] Made some progressgit commit --- spec/chunk.js | 5 +++++ spec/min.js | 7 +++---- spec/replace.js | 3 +++ spec/reversearray.js | 3 +++ spec/uppercase.js | 3 +++ spec/upperfirst.js | 6 ++++++ test/chunk.test.js | 16 ++++++++++++++++ test/replace.test.js | 20 ++++++++++++++++++++ test/reversearray.test.js | 9 +++++++++ test/uppercase.test.js | 8 ++++++++ test/upperfirst.test.js | 8 ++++++++ 11 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 spec/chunk.js create mode 100644 spec/replace.js create mode 100644 spec/reversearray.js create mode 100644 spec/uppercase.js create mode 100644 spec/upperfirst.js create mode 100644 test/chunk.test.js create mode 100644 test/replace.test.js create mode 100644 test/reversearray.test.js create mode 100644 test/uppercase.test.js create mode 100644 test/upperfirst.test.js diff --git a/spec/chunk.js b/spec/chunk.js new file mode 100644 index 0000000..9c0acac --- /dev/null +++ b/spec/chunk.js @@ -0,0 +1,5 @@ +// module.exports = function (a, num ){ +// while(a.length) { +// return (a.splice(0,3)); +// } +// } diff --git a/spec/min.js b/spec/min.js index 51a0b90..f6bedca 100644 --- a/spec/min.js +++ b/spec/min.js @@ -1,7 +1,6 @@ module.exports = function min( inputArray ) { - if(Array.isArray(inputArray)){ + return Math.min.apply(null, inputArray) - } else { - return - } + + } diff --git a/spec/replace.js b/spec/replace.js new file mode 100644 index 0000000..696f783 --- /dev/null +++ b/spec/replace.js @@ -0,0 +1,3 @@ +module.exports = function (sentence, word1, word2){ + return sentence.replace(word1, word2) +} diff --git a/spec/reversearray.js b/spec/reversearray.js new file mode 100644 index 0000000..7add60a --- /dev/null +++ b/spec/reversearray.js @@ -0,0 +1,3 @@ +module.exports = function reversearray( array ) { + return array.reverse() +} diff --git a/spec/uppercase.js b/spec/uppercase.js new file mode 100644 index 0000000..4b0e036 --- /dev/null +++ b/spec/uppercase.js @@ -0,0 +1,3 @@ +module.exports = function uppercase( anyString ) { + return anyString.toUpperCase() + } diff --git a/spec/upperfirst.js b/spec/upperfirst.js new file mode 100644 index 0000000..0a9ec22 --- /dev/null +++ b/spec/upperfirst.js @@ -0,0 +1,6 @@ +module.exports = function upperfirst( str ) { + function substr(match) { + return match.toUpperCase() + } + return str.replace(/\b[a-z]/g, substr) + } diff --git a/test/chunk.test.js b/test/chunk.test.js new file mode 100644 index 0000000..3badd40 --- /dev/null +++ b/test/chunk.test.js @@ -0,0 +1,16 @@ +// var {expect} = require("chai") +// var chunk = require("../spec/chunk") +// var a = [1 , 2 , 3, 4, 5] +// +// // var createGroupedArray = function (arr, chunkSize) { +// // var groups = [1 , 2 , 3, 4, 5], i; +// // for (i = 3; i < arr.length; i += chunkSize) { +// // groups.push(arr.slice(i, i + chunkSize)) +// // } +// // } +// +// describe("chunk", function() { +// it("should split array into chunks according to selected size", function() { +// expect(chunk([1 , 2, 3, 4, 5])).to.eql([[1 , 2 , 3],[4 , 5]]) +// }) +// }) diff --git a/test/replace.test.js b/test/replace.test.js new file mode 100644 index 0000000..96087d6 --- /dev/null +++ b/test/replace.test.js @@ -0,0 +1,20 @@ +var {expect} = require("chai") +var replace = require('../spec/replace') +var sentence = 'We are at the ship yard' +var word1 = "ship" +var word2 = "house" +// var str = "Mr Blue has a blue house and a blue car"; +// var res = str.replace(/blue/g, "red"); + + describe("replace", function() { + it("should replace one word for another", function() { + expect(replace(sentence, word1, word2)) + .to.equal('We are at the house yard') + }) + }) + // function myFunction() { + +// var str = document.getElementById("demo").innerHTML; +// var res = str.replace("Microsoft", "W3Schools"); +// document.getElementById("demo").innerHTML = res; +// } diff --git a/test/reversearray.test.js b/test/reversearray.test.js new file mode 100644 index 0000000..e29a20b --- /dev/null +++ b/test/reversearray.test.js @@ -0,0 +1,9 @@ +var {expect} = require("chai") +var reversearray = require("../spec/reversearray") +var array = [3 , 2 , 1] + +describe("reversearray", function() { + it("should reverse elements in array", function() { + expect(reversearray([3 , 2 , 1])).to.eql([1 , 2 , 3]) + }) +}) diff --git a/test/uppercase.test.js b/test/uppercase.test.js new file mode 100644 index 0000000..1566e90 --- /dev/null +++ b/test/uppercase.test.js @@ -0,0 +1,8 @@ +var {expect} = require("chai") +var uppercase = require("../spec/uppercase") + +describe("uppercase", function() { + it("should capitalize all letters in string", function() { + expect(uppercase("Hello World")).to.eql("HELLO WORLD") + }) +}) diff --git a/test/upperfirst.test.js b/test/upperfirst.test.js new file mode 100644 index 0000000..37b046e --- /dev/null +++ b/test/upperfirst.test.js @@ -0,0 +1,8 @@ +var {expect} = require("chai") +var upperfirst = require("../spec/upperfirst") + +describe("upperfirst", function() { + it("should capitalize first letter of each word in string", function() { + expect(upperfirst("hello world")).to.equal("Hello World") + }) +}) From 7c8ebab222aace9c8ace018995fe30efb1bfe89e Mon Sep 17 00:00:00 2001 From: rogercamps Date: Fri, 17 Feb 2017 09:01:52 -0800 Subject: [PATCH 09/12] added random repeat and camelcase, but they need some tweaking --- spec/camelcase.js | 6 ++++++ spec/random.js | 6 ++++++ spec/repeat.js | 7 +++++++ spec/upperfirst.js | 4 ++-- test/camelcase.test.js | 9 +++++++++ test/multiply.test.js | 2 +- test/random.test.js | 10 ++++++++++ test/repeat.test.js | 13 +++++++++++++ 8 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 spec/camelcase.js create mode 100644 spec/random.js create mode 100644 spec/repeat.js create mode 100644 test/camelcase.test.js create mode 100644 test/random.test.js create mode 100644 test/repeat.test.js diff --git a/spec/camelcase.js b/spec/camelcase.js new file mode 100644 index 0000000..1d14b97 --- /dev/null +++ b/spec/camelcase.js @@ -0,0 +1,6 @@ +module.exports =function ( str ) { + function upperCase(match) { + return match.toUpperCase() + } + return str.replace(/\b[a-z]/g, upperCase).replace(/\s/g, '') +} diff --git a/spec/random.js b/spec/random.js new file mode 100644 index 0000000..358b87b --- /dev/null +++ b/spec/random.js @@ -0,0 +1,6 @@ +// module.exports = function(myArray) { +// function(){ +// var result = myArray[Math.floor(Math.random() * myArray.length)] +// return result +// } +// } diff --git a/spec/repeat.js b/spec/repeat.js new file mode 100644 index 0000000..61d32ac --- /dev/null +++ b/spec/repeat.js @@ -0,0 +1,7 @@ +module.exports = function (str, n){ + var utilities = { + repeat: function(str, n) { + return (new Array(n + 1)).join(str); + } + } +} diff --git a/spec/upperfirst.js b/spec/upperfirst.js index 0a9ec22..da608d4 100644 --- a/spec/upperfirst.js +++ b/spec/upperfirst.js @@ -2,5 +2,5 @@ module.exports = function upperfirst( str ) { function substr(match) { return match.toUpperCase() } - return str.replace(/\b[a-z]/g, substr) - } + return str.replace(/\b[a-z]/g, substr) + } diff --git a/test/camelcase.test.js b/test/camelcase.test.js new file mode 100644 index 0000000..bd5d556 --- /dev/null +++ b/test/camelcase.test.js @@ -0,0 +1,9 @@ +var {expect} = require("chai") +var camelcase = require('../spec/camelcase') +var str = "This Should Be Camelized" + +describe("camelcase", function() { + it("should camelize any sentence", function() { + expect(camelcase(str)).to.equal("ThisShouldBeCamelized") + }) +}) diff --git a/test/multiply.test.js b/test/multiply.test.js index 1d9d9b2..1816816 100644 --- a/test/multiply.test.js +++ b/test/multiply.test.js @@ -3,6 +3,6 @@ var multiply = require("../spec/multiply") describe("multiply", function() { it("should multiply num1 by num2", function() { - expect(multiply( 1 , 2 )).to.eql(2) + expect(multiply( 3 , 2 )).to.eql(6) }) }) diff --git a/test/random.test.js b/test/random.test.js new file mode 100644 index 0000000..880d8ab --- /dev/null +++ b/test/random.test.js @@ -0,0 +1,10 @@ +// var {expect} = require("chai") +// var random = require('../spec/random') +// +// var myArray = ['this','is','hard'] +// +// describe("random", function() { +// it("should find a random element in an array", function() { +// expect(random(myArray)).to.equal(result) +// }) +// }) diff --git a/test/repeat.test.js b/test/repeat.test.js new file mode 100644 index 0000000..f7c7347 --- /dev/null +++ b/test/repeat.test.js @@ -0,0 +1,13 @@ +var {expect} = require("chai") +var repeat = require('../spec/repeat') + +var str = 'cash' +var n = 5 + + + +describe("repeat", function() { + it("should repeat the given string n times", function() { + expect(repeat(str, n)).to.equal('cashcashcashcashcash') + }) +}) From b5c1ae2ab102e14d378bd77e7a35f2bc0e5ce796 Mon Sep 17 00:00:00 2001 From: Learner Date: Fri, 17 Feb 2017 09:28:52 -0800 Subject: [PATCH 10/12] files to be overwritten --- spec/camelcase.js | 6 ++++++ test/camelcase.test.js | 11 +++++++++++ 2 files changed, 17 insertions(+) create mode 100644 spec/camelcase.js create mode 100644 test/camelcase.test.js diff --git a/spec/camelcase.js b/spec/camelcase.js new file mode 100644 index 0000000..e905bb7 --- /dev/null +++ b/spec/camelcase.js @@ -0,0 +1,6 @@ +module.exports =function ( sentence ) { + function camelcase(match) { + return match.toUpperCase() + } + return sentence.replace(/\b[a-z]/g, camelcase).replace(/\s/g, '') + } diff --git a/test/camelcase.test.js b/test/camelcase.test.js new file mode 100644 index 0000000..e9a1eab --- /dev/null +++ b/test/camelcase.test.js @@ -0,0 +1,11 @@ +var {expect} = require("chai") +var camelcase = require('../spec/camelcase') +var sentence = "This Should Be Camelized" + +// var upperFirst = require('../spec/upperFirst') + + describe("camelcase", function() { + it("should camelize any sentece", function() { + expect(camelcase(sentence).to.eql("thisShouldBeCamelized")) + }) + }) From ef5d36a482f628e6026b6bf276621ad64d2a5cda Mon Sep 17 00:00:00 2001 From: Learner Date: Fri, 17 Feb 2017 16:32:42 -0800 Subject: [PATCH 11/12] Completed chunk function and worked on join function (still needs tweeking) --- public/index.html | 5 ++++ public/javascripts/index.js | 0 spec/chunk.js | 49 ++++++++++++++++++++++++++++++++++--- spec/join.js | 7 ++++++ test/chunk.test.js | 27 +++++++++----------- test/join.test.js | 9 +++++++ test/repeat.test.js | 26 ++++++++++---------- 7 files changed, 90 insertions(+), 33 deletions(-) create mode 100644 public/index.html create mode 100644 public/javascripts/index.js create mode 100644 spec/join.js create mode 100644 test/join.test.js diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..684809f --- /dev/null +++ b/public/index.html @@ -0,0 +1,5 @@ + + This is only a Test + + + diff --git a/public/javascripts/index.js b/public/javascripts/index.js new file mode 100644 index 0000000..e69de29 diff --git a/spec/chunk.js b/spec/chunk.js index 9c0acac..3c74658 100644 --- a/spec/chunk.js +++ b/spec/chunk.js @@ -1,5 +1,46 @@ -// module.exports = function (a, num ){ -// while(a.length) { -// return (a.splice(0,3)); -// } +module.exports = function (list, size=2) { + + if (list.isArray /*&& !== 'string'*/){ + return [] + } + var newList = [] + for(var i = 0; i < list.length ; i+=size) { + var subArray = [] + for(var j = 0; j < size ; j++) { + if (list[i+j]) { + subArray.push(list[i+j]) + } + + } + newList.push(subArray) + } + + return newList +} +// } +// } +// +// } +// +// +// + + + + + + + + + + +// var arrays = [] +// for (i = 3; i < list.length; i += size) { +// var newArray = [] +// for (var j = 0; j < size.length; j++) { +// groups.push(list[i+j]) +// } +// arrays.push(newArray) +// } +// return arrays // } diff --git a/spec/join.js b/spec/join.js new file mode 100644 index 0000000..df3e221 --- /dev/null +++ b/spec/join.js @@ -0,0 +1,7 @@ +module.exports = function (array) { + for (i = 0; i < array.length; i++) { + + + } + return array.filter(/\s/g,'~') +} diff --git a/test/chunk.test.js b/test/chunk.test.js index 3badd40..7170c96 100644 --- a/test/chunk.test.js +++ b/test/chunk.test.js @@ -1,16 +1,11 @@ -// var {expect} = require("chai") -// var chunk = require("../spec/chunk") -// var a = [1 , 2 , 3, 4, 5] -// -// // var createGroupedArray = function (arr, chunkSize) { -// // var groups = [1 , 2 , 3, 4, 5], i; -// // for (i = 3; i < arr.length; i += chunkSize) { -// // groups.push(arr.slice(i, i + chunkSize)) -// // } -// // } -// -// describe("chunk", function() { -// it("should split array into chunks according to selected size", function() { -// expect(chunk([1 , 2, 3, 4, 5])).to.eql([[1 , 2 , 3],[4 , 5]]) -// }) -// }) +var {expect} = require("chai") +var chunk = require("../spec/chunk") // change spec and also folder +// name from spec to source + +describe("chunk", function() { + it("should split array into chunks according to selected size", function() { + expect(chunk([1 , 2, 3, 4, 5], 3)).to.eql([[1 , 2 , 3],[4 , 5]]) + }) +}) +// Nest a for loop create variable for new array +//iterate through the new array to handle chunk size diff --git a/test/join.test.js b/test/join.test.js new file mode 100644 index 0000000..448c27c --- /dev/null +++ b/test/join.test.js @@ -0,0 +1,9 @@ +var {expect} = require("chai") +var join = require('../spec/join') +var array = ['this' , 'should' , 'be' , 'easy'] + +describe("join", function() { + it("should convert all elements into string with designated separator", function() { + expect(join(array)).to.equal('this~should~be~easy') + }) +}) diff --git a/test/repeat.test.js b/test/repeat.test.js index f7c7347..3e0479c 100644 --- a/test/repeat.test.js +++ b/test/repeat.test.js @@ -1,13 +1,13 @@ -var {expect} = require("chai") -var repeat = require('../spec/repeat') - -var str = 'cash' -var n = 5 - - - -describe("repeat", function() { - it("should repeat the given string n times", function() { - expect(repeat(str, n)).to.equal('cashcashcashcashcash') - }) -}) +// var {expect} = require("chai") +// var repeat = require('../spec/repeat') +// +// var str = 'cash' +// var n = 5 +// +// +// +// describe("repeat", function() { +// it("should repeat the given string n times", function() { +// expect(repeat(str, n)).to.equal('cashcashcashcashcash') +// }) +// }) From 4e60ac523b131884879b2c0b1c84b7a3eb1c5957 Mon Sep 17 00:00:00 2001 From: DeBray Carpenter Date: Tue, 21 Feb 2017 09:04:32 -0800 Subject: [PATCH 12/12] final commits, for npm modules --- spec/chunk.js | 29 +---------------------------- spec/join.js | 14 +++++++------- test/join.test.js | 18 +++++++++--------- 3 files changed, 17 insertions(+), 44 deletions(-) diff --git a/spec/chunk.js b/spec/chunk.js index 3c74658..1e5e411 100644 --- a/spec/chunk.js +++ b/spec/chunk.js @@ -1,6 +1,6 @@ module.exports = function (list, size=2) { - if (list.isArray /*&& !== 'string'*/){ + if (list.isArray){ return [] } var newList = [] @@ -17,30 +17,3 @@ module.exports = function (list, size=2) { return newList } -// } -// } -// -// } -// -// -// - - - - - - - - - - -// var arrays = [] -// for (i = 3; i < list.length; i += size) { -// var newArray = [] -// for (var j = 0; j < size.length; j++) { -// groups.push(list[i+j]) -// } -// arrays.push(newArray) -// } -// return arrays -// } diff --git a/spec/join.js b/spec/join.js index df3e221..79330ea 100644 --- a/spec/join.js +++ b/spec/join.js @@ -1,7 +1,7 @@ -module.exports = function (array) { - for (i = 0; i < array.length; i++) { - - - } - return array.filter(/\s/g,'~') -} +// module.exports = function (array) { +// for (i = 0; i < array.length; i++) { +// +// +// } +// return array.filter(/\s/g,'~') +// } diff --git a/test/join.test.js b/test/join.test.js index 448c27c..9a0d86d 100644 --- a/test/join.test.js +++ b/test/join.test.js @@ -1,9 +1,9 @@ -var {expect} = require("chai") -var join = require('../spec/join') -var array = ['this' , 'should' , 'be' , 'easy'] - -describe("join", function() { - it("should convert all elements into string with designated separator", function() { - expect(join(array)).to.equal('this~should~be~easy') - }) -}) +// var {expect} = require("chai") +// var join = require('../spec/join') +// var array = ['this' , 'should' , 'be' , 'easy'] +// +// describe("join", function() { +// it("should convert all elements into string with designated separator", function() { +// expect(join(array)).to.equal('this~should~be~easy') +// }) +// })