forked from AlreadyBored/basic-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} | ||
} | ||
|
||
}; |