Skip to content

Instantly share code, notes, and snippets.

View IPRIT's full-sized avatar
💅

Alexander Belov IPRIT

💅
View GitHub Profile
function duckCount() {
return Array.prototype.slice.call(arguments).filter(function(obj) {
return Object.prototype.hasOwnProperty.call(obj, 'quack')
}).length
}
module.exports = duckCount;
@IPRIT
IPRIT / program.js
Created April 11, 2015 15:18
Example own implemenation of reduce function similar to use Array#reduce
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;
@IPRIT
IPRIT / program.js
Created April 11, 2015 14:58
Reduce example
var util = require('util');
function countWords(inputWords) {
return inputWords.reduce(function (prev, cur) {
prev[cur] = ++prev[cur] || 1;
return prev;
}, {});
}
module.exports = countWords;
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;
}
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;
});
});
};
}
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),
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),
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);
});
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]);
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) {