Skip to content

Commit

Permalink
feat: add solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
AV-Shell committed Mar 22, 2020
1 parent 46532f2 commit 22e5a4f
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 19 deletions.
16 changes: 8 additions & 8 deletions src/carbon-dating.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const MODERN_ACTIVITY= 15;
const HALF_LIFE_PERIOD= 5730;
const MODERN_ACTIVITY = 15;
const HALF_LIFE_PERIOD = 5730;

const CONSOLE_LOG_ENABLE = false;

module.exports = function dateSample(string_data/* sampleActivity */) {
// throw 'Not implemented';
if (CONSOLE_LOG_ENABLE) console.log(string_data);
if (CONSOLE_LOG_ENABLE) console.log(string_data);
if (!((typeof string_data) === "string")) {
return false;
}

let num = parseFloat(string_data);
if (CONSOLE_LOG_ENABLE) console.log(num);
if (!((num < MODERN_ACTIVITY) && (num>0))) {
let num = parseFloat(string_data);
if (CONSOLE_LOG_ENABLE) console.log(num);
if (!((num < MODERN_ACTIVITY) && (num > 0))) {
return false;
}

let age = Math.ceil(5730*Math.log(MODERN_ACTIVITY/num)/0.693);
if (CONSOLE_LOG_ENABLE) console.log(age);
let age = Math.ceil(HALF_LIFE_PERIOD * Math.log(MODERN_ACTIVITY / num) / 0.693);
if (CONSOLE_LOG_ENABLE) console.log(age);
return age;
};
30 changes: 28 additions & 2 deletions src/extended-repeater.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
module.exports = function repeater(/* str, options */) {
module.exports = function repeater(str, options) {


repeatTimes = 'repeatTimes' in options ? options.repeatTimes : 0;
separator = 'separator' in options ? options.separator : '+';
addition = 'addition' in options ? options.addition : '';
additionRepeatTimes = 'additionRepeatTimes' in options ? options.additionRepeatTimes : 0;
additionSeparator = 'additionSeparator' in options ? options.additionSeparator : '|';

outstring = '';
let i = 0;
do {
i++;
if (i > 1) {
outstring = outstring + separator;
}
let add_str = '';
let j = 0;
do {
j++;
if (j > 1) {
add_str = add_str + additionSeparator;
}
add_str = add_str + addition
} while (j < additionRepeatTimes);
outstring = outstring + str + add_str;
} while (i < repeatTimes);
return outstring;
throw 'Not implemented';
// remove line with error and write your code here
};

14 changes: 11 additions & 3 deletions src/hanoi-tower.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
module.exports = function calculateHanoi(/* disksNumber, turnsSpeed */) {
throw 'Not implemented';
// remove line with error and write your code here
module.exports = function calculateHanoi( disksNumber, turnsSpeed ) {
let obj = {
'turns' : 0 ,
'seconds' : 0,
}
// console.log ('hanoi in', disksNumber, turnsSpeed );
for(let i=1; i<=disksNumber;i++){
obj.turns = obj.turns*2 +1;
}
obj.seconds = obj.turns/ (turnsSpeed/ 3600);
return obj;
}
18 changes: 15 additions & 3 deletions src/recursive-depth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
module.exports = class DepthCalculator {
calculateDepth(/* arr */) {
throw 'Not implemented';
// remove line with error and write your code here
calculateDepth(arr) {
// console.log (arr)
if (!(Array.isArray(arr))) {
return 0;
} else {
let max = 0;
arr.forEach(element => {
if (Array.isArray(element)) {
let tmp = this.calculateDepth(element);
max = tmp > max ? tmp : max;
}
});
max++;
return max;
}
}
};
56 changes: 53 additions & 3 deletions src/what-season.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
module.exports = function getSeason(/* date */) {
throw 'Not implemented';
// remove line with error and write your code here
module.exports = function getSeason(date) {
// console.log('in', date);
let testDate = new Date;
// for(let prop in testDate){
// console.log('test a 1',prop);
// }
for( let prop in date){
// console.log('test a 2',prop);
throw 'Error';
}
if (date == null) {
return 'Unable to determine the time of year!';
// remove line with error and write your code here
}
if (testDate.__proto__ != date.__proto__) {
throw 'Error';
}

let month_num = date.getMonth();
// console.log('month_num', month_num);
{
switch (month_num) {
case 0:
case 1:
case 11:
{
console.log('winter');
return 'winter';
}
case 2:
case 3:
case 4:
{
console.log('spring');
return 'spring';
}
case 5:
case 6:
case 7:
{
console.log('summer');
return 'summer';
}
case 8:
case 9:
case 10:
{
console.log('fall');
return 'fall';
}
}
}

};

0 comments on commit 22e5a4f

Please sign in to comment.