starting state

This commit is contained in:
Märt Kalmo 2017-03-30 14:12:43 +03:00
parent 2056262a00
commit cdd07ba12f
6 changed files with 10 additions and 70 deletions

14
ex1.js
View File

@ -2,18 +2,4 @@
var array = [1, 2, 3, 4, 5, 6];
array = filter(array, function (each) {
return each % 2 === 0;
});
console.log('Even numbers: ' + array);
function filter(array, predicate) {
var result = [];
for (var i = 0; i < array.length; i++) {
if (predicate(array[i])) {
result.push(array[i]);
}
}
return result;
}

6
ex2.js
View File

@ -2,11 +2,5 @@
var array = [1, 2, 3, 4, 5, 6];
array = array.filter(function (each) {
return each % 2 === 0;
}).map(function (each) {
return each * each;
});
console.log('Even numbers squared: ' + array);

6
ex3.js
View File

@ -9,11 +9,5 @@ var array = [
{ id: 6, selected: false }
];
array = array.filter(function (each) {
return each.selected;
}).map(function (each) {
return each.id;
});
console.log('Ids of selected objects: ' + array);

18
ex4.js
View File

@ -1,20 +1,2 @@
'use strict';
function Person(name) {
this.name = name;
}
Person.prototype.getName = function () {
return this.name;
};
Person.prototype.setName = function (name) {
return this.name = name;
};
var person = new Person('Jack');
var person2 = new Person('Jack');
console.log(person.getName());
console.log(Object.keys(person));
console.log(Object.keys(person.__proto__));

6
ex5.js
View File

@ -1,12 +1,6 @@
'use strict';
factorial(5, function (res) {
console.log('res: ' + res);
});
function factorial(n, callback) {
if (n < 0) {
throw 'illegal argument'

30
ex6.js
View File

@ -3,29 +3,19 @@
var request = require("request");
get('/api/persons/2948', function(data) {
var code = data.code;
var name = data.name;
get('/api/health-insurance/' + code, function(data) {
var isInsured = data.isInsured;
get('/api/tax-debt/' + code, function(data) {
var debt = data.debt;
var person = {
name : name,
isInsured: isInsured,
taxDebt: debt
};
console.log(person);
});
});
console.log(data);
});
// helper function
function get(url, cb) {
request('http://localhost:3000' + url, function(error, response, body) {