This file contains hidden or 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
| function duckCount() { | |
| return Array.prototype.slice.call(arguments).filter(function(obj) { | |
| return Object.prototype.hasOwnProperty.call(obj, 'quack') | |
| }).length | |
| } | |
| module.exports = duckCount; |
This file contains hidden or 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
| function reduce(arr, fn, prev) { | |
| prev = prev || {}; | |
| if (!arr.length) { | |
| return prev; | |
| } | |
| var cur = fn(prev, arr.shift()); | |
| return reduce(arr, fn, cur); | |
| } | |
| module.exports = reduce; |
This file contains hidden or 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 util = require('util'); | |
| function countWords(inputWords) { | |
| return inputWords.reduce(function (prev, cur) { | |
| prev[cur] = ++prev[cur] || 1; | |
| return prev; | |
| }, {}); | |
| } | |
| module.exports = countWords; |
This file contains hidden or 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 util = require('util'); | |
| function countWords(inputWords) { | |
| return inputWords.reduce(function (prev, cur) { | |
| if (!util.isObject(prev)) { | |
| var obj = {}; | |
| obj[prev] = 1; | |
| obj[cur] = 1; | |
| return obj; | |
| } |
This file contains hidden or 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
| function checkUsersValid(goodUsers) { | |
| return function(submittedUsers) { | |
| return submittedUsers.every(function(el) { | |
| var cur_id = el.id; | |
| return goodUsers.some(function(el) { | |
| return el.id === cur_id; | |
| }); | |
| }); | |
| }; | |
| } |
This file contains hidden or 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 args = process.argv.slice(2); | |
| var http = require('http'); | |
| var url = require('url'); | |
| var server = http.createServer(function(req, res) { | |
| if (req.method != 'GET') { | |
| res.end("Allows to use only GET HTTP request"); | |
| return; | |
| } | |
| var parsedUrl = url.parse(req.url, true), |
This file contains hidden or 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 args = process.argv.slice(2); | |
| var http = require('http'); | |
| var url = require('url'); | |
| var server = http.createServer(function(req, res) { | |
| if (req.method != 'GET') { | |
| res.end("Alows to use only GET HTTP request"); | |
| return; | |
| } | |
| var parsedUrl = url.parse(req.url, true), |
This file contains hidden or 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 args = process.argv.slice(2); | |
| var http = require('http'); | |
| var map = require('through2-map'); | |
| var server = http.createServer(function(req, res) { | |
| req.pipe(map(function(chunk) { | |
| return chunk.toString().toUpperCase(); | |
| })).pipe(res); | |
| //console.log(req.pipe); | |
| }); |
This file contains hidden or 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 args = process.argv.slice(2); | |
| var net = require('net'); | |
| var strftime = require('strftime'); | |
| net.createServer(function(socket) { | |
| socket.end(strftime('%F %R') + '\n'); | |
| }).listen(+args[0]); |
This file contains hidden or 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 args = process.argv.slice(2); | |
| var httpPipe = require('./http_pipe'); | |
| var queue = [], cur; | |
| var httpGet = function(url) { | |
| function callback(err, data) { | |
| if (err) throw err; | |
| console.log(data); | |
| if (queue.length) { |