-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Test fix #2
Changes from all commits
4f2bf4b
a45bb93
811f3b4
afc44ad
f11d995
cb05242
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
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); | ||
} | ||
|
||
Formulas.pushToArray = function (a, b) { | ||
return a.push(b); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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')) | ||
}()); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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"); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
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.