Skip to content

Test fix #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
16 changes: 16 additions & 0 deletions chapter1/bank-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,34 @@ var BankSecurity = {

var BankAccount = {
balance: 0,
<<<<<<< HEAD

deposit: function (money) {
this.balance = this.balance + money;
return this.balance;
},

=======
deposit: function (money) {
this.balance = this.balance + money;
},
>>>>>>> 4f8b4060407687a11e26eb422cb4e79289fe505c
widthraw: function (cash) {
this.balance = this.balance - cash;
return this.balance;
}
<<<<<<< HEAD
}
=======
};
>>>>>>> 4f8b4060407687a11e26eb422cb4e79289fe505c

module.exports = {
BankAccount: BankAccount,
BankSecurity: BankSecurity
}
<<<<<<< HEAD
=======


>>>>>>> 4f8b4060407687a11e26eb422cb4e79289fe505c
95 changes: 75 additions & 20 deletions chapter1/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,88 @@
(function(){
let Formulas = {};

console.log('Hello world');
Formulas.add = function (a, b) {
return a + b;
}

let add = function(a, b){
return a + b;
Formulas.divideMultiply = function (a, b) {
if (b == 0) {
return undefined;
}
return a * a / b;
}

let o = {
key: { key: { key: 42 }}
};
Formulas.roundNumbers = function (a) {
return Math.round(a);
}

let arr = [1,2,3,4,5];

console.log(arr[4])
Formulas.sinTimesCos = function (a) {
return Math.sin(a) * Math.cos(a);
}

Formulas.parseNumberFromString = function (a) {
return parseFloat(a);
}

Formulas.findObjectValueByKey = function (obj, key) {
let i;
let j;
let p;

for (i = 0; i < Object.keys(obj).length; i++) {
if (Object.keys(obj)[i] === key) {
return Object.values(obj)[i];
}
if (typeof Object.values(obj)[i] === "object" && (Object.values(obj)[i] !== null)) {
var newObject = Object.values(obj)[i];
for (j = 0; j < Object.keys(newObject).length; j++) {
if (Object.keys(newObject)[j] === key) {
return Object.values(newObject)[j];
}
if (typeof Object.values(newObject)[j] === "object" && (Object.values(newObject)[j] !== null)) {
var newObject2 = Object.values(newObject)[j];
for (p = 0; p < Object.keys(newObject2).length; p++) {
if (Object.keys(newObject2)[p] === key) {
return Object.values(newObject2)[p];
}
}
}
}
}
}
}

Formulas.parseJSON = function (a) {
return JSON.parse(a);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe to reason to wrap this stuff in function.

}

Formulas.pushToArray = function (a, b) {
return a.push(b);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

}

let blablaFunction = function(phrase) {
return function(){
console.log('Phrase ' + phrase);
}
Formulas.squareArrayValues = function (a) {
var newArr = a;
for (var i = 0; i < newArr.length; i++) {
newArr[i] = newArr[i] * newArr[i];
}
return a;
}

let composedBlablaFunction = function(blaFunction) {
console.log('Get some air in your lungs!');
blaFunction();
console.log('Now you can rest!')
Formulas.sortArray = function (a) {
return a.sort(Formulas.sortNumbers)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not move one-liners to methods unless there is some specific logic there.

}

Formulas.sortNumbers = function (a, b) {
return a - b;
}

Formulas.reverseString = function (a) {
var newString = "";
for (var i = a.length - 1; i >= 0; i--) {
newString += a[i];
}
return newString;
}

module.exports = Formulas;


composedBlablaFunction(blablaFunction('Hello world'))
}());
24 changes: 12 additions & 12 deletions chapter1/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chapter1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "./node_modules/mocha/bin/mocha"
"test": "mocha"
},
"author": "",
"license": "MIT",
Expand Down
12 changes: 12 additions & 0 deletions chapter1/test/bank-account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ var BankAccount = require('../bank-account').BankAccount;

describe('Bank account', () => {
it('should have no money on deposit in the beginning', () => {
<<<<<<< HEAD
assert.equal(BankAccount.balance, 0);
});

it('should be able to withdraw money', () => {
assert.equal(BankAccount.widthraw(20), -20);
});

it('should be able to deposit money', () => {
assert.equal(BankAccount.deposit(30), 10);
=======

var obj = {
foo: "hello world",
Expand All @@ -14,5 +25,6 @@ describe('Bank account', () => {
obj.fn(1,2,3,4,45,6, "", {}, [], Infinity,1,23,1,12,12,3,12,3123,123,123,123,123,123,123);

//assert.equal(BankAccount.balance, 0);
>>>>>>> 4f8b4060407687a11e26eb422cb4e79289fe505c
});
})
101 changes: 62 additions & 39 deletions chapter1/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,108 @@
var assert = require('assert');
var Formulas = require('../index.js');

describe('JS Basics', function () {
describe('Numbers', function () {
it('should be able to add numbers', function () {
var a = 45;
var b = 54;
assert.equal(Formulas.add(a, b), 99);
});

<<<<<<< HEAD
it('should be able to divide and multiply number', function () {
var a = 4;
var b = 2;
assert.equal(Formulas.divideMultiply(a, b), 8);
=======
xdescribe('JS Basics', function() {
describe('Numbers', function() {
it('should be able to add number', function() {
var a = 42.9902822;
var b = 43.2929112;
assert.equal(a + b, 99);
>>>>>>> 4f8b4060407687a11e26eb422cb4e79289fe505c
});

it('should be able to divide and multiply number', function() {
var a = 42.94;
it('should return undefined if divided by 0', function () {
var a = 4;
var b = 0;

assert.equal(a * a / b, 42);
assert.equal(Formulas.divideMultiply(a, b), undefined);
});

it('should be able to round numbers', function() {
var a = 42.94;
assert.equal(a, 42);
it('should be able to round numbers', function () {
var a = 42.94;
assert.equal(Formulas.roundNumbers(a), 43);
});

it('should be able to find sin(x) * cos(x)', function() {
var a = 42;
assert.equal(a, 1);
it('should be able to find sin(x)*cos(x)', function () {
var a = 0;
assert.equal(Formulas.sinTimesCos(a), 0);
});

it('should be able to parse number form string', function() {
it('should be able to parse number form string', function () {
var price = "9.99 $"
assert.equal(price, 9.99);
assert.equal(Formulas.parseNumberFromString(price), 9.99);
});
});


describe('Objects', function() {
it('should be find object value by key', function() {
var obj = { a: {b: { d: "foo" }}, c: 42 }
assert.equal(obj, "foo");
describe('Objects', function () {
it('should be able to find object value by key', function () {
var obj = { a: { b: { d: "foo" } }, c: 42 };
assert.equal(Formulas.findObjectValueByKey(obj, 'd'), "foo");
});

it('should be find object value by dynamic key', function() {
var obj = { a: {b: { d: "foo" }}, c: 42 }
assert.equal(obj["hm"], 42);
it('should be able to find object value by dynamic key', function () {
var obj = { a: { b: { d: "foo" } }, c: 42 }
assert.equal(Formulas.findObjectValueByKey(obj, 'c'), 42);;
});

it('should be parse object from json', function() {
it('should be able to parse object from json', function () {
var json = '{"ok":true,"user_lessons":[{"user_lesson_id":408097171313,"state":"completed","skip":false,"lesson_id":1,"date_start":1533108640,"tasks":[{"user_task_id":407936828624,"state":"skipped","current_step":"","task_id":1},{"user_task_id":408791535509,"state":"skipped","current_step":"","task_id":2},{"user_task_id":409970847238,"state":"skipped","current_step":"","task_id":3}]}]}'
var dateStart = 42;
var parsedJSON = Formulas.parseJSON(json);
var dateStart = parsedJSON.user_lessons[0].date_start;
assert.equal(dateStart, 1533108640);
});

it('should be set objet key', function() {
var obj = { a: {b: { d: "foo" }}, c: 42 }
it('should be able to set object key', function () {
var obj = { a: { b: { d: "foo" } }, c: 42 }
obj.a.b = "Js Rocks!";
assert.equal(obj.a.b, "Js Rocks!")
});
});


describe('Arrays', function() {
it('should be access array by index', function() {
var arrray = [1,2,3,4,5,6,7,8,9]
assert.equal(arrray, 5);
describe('Arrays', function () {
it('should be able to access array by index', function () {
var arrray = [1, 2, 3, 4, 5, 6, 7, 8, 9];
assert.equal(arrray[4], 5);
});

it('should to push and pop from array', function() {
var arrray = [1,2,3,4,5,6,7,8,9]
assert.equal(arrray.length, 10);
it('should to push and pop from array', function () {
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9];
Formulas.pushToArray(array, 10);
assert.equal(array.length, 10);
});

it('should be able to output square of array values', function() {
assert.equal()
it('should be able to output square of array values', function () {
var arr = [1, 2, 3, 4, 5];
var expectedArr = [1, 4, 9, 16, 25];
var newArr = Formulas.squareArrayValues(arr);
assert.deepEqual(newArr, expectedArr);
});

it('should be able to sort array', function() {
var arr = [23,23,4,5,123,7,32,13,13,9]
assert.equal(arr, []);
it('should be able to sort array', function () {
var arr = [23, 23, 4, 5, 123, 7, 32, 13, 13, 9];
var expectedArr = [4, 5, 7, 9, 13, 13, 23, 23, 32, 123];
var sortedArr = Formulas.sortArray(arr);
assert.deepEqual(sortedArr, expectedArr);
});

it('should be able to reverse string', function() {

var string = "I love corgies!"
assert.equal(string, "!seigroc evol I")
it('should be able to reverse string', function () {
var string = "I love corgies!";
var newString = Formulas.reverseString(string);
assert.equal(newString, "!seigroc evol I");
});
});
});
Loading