-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from harl-i/module5-task2
- Loading branch information
Showing
1 changed file
with
18 additions
and
23 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,29 +1,24 @@ | ||
//Задача №1. Функция для проверки длины строки. | ||
function checkStringLength(string, maxLength) { | ||
return string.length <= maxLength; | ||
} | ||
//5.16. Функции возвращаются | ||
|
||
//Задача №2. Функция для проверки, является ли строка палиндромом. | ||
function checkPalindrome(string) { | ||
const formattedString = string.replaceAll(' ', '').toLowerCase(); | ||
function checkMeetingTimeframe (startWorkingDay, endWorkingDay, beginningMeeting, durationMeeting) { | ||
const startWorkingDayInMinutes = convertToMinutes(startWorkingDay); | ||
const endWorkingDayInMinutes = convertToMinutes(endWorkingDay); | ||
const beginningMeetingInMinutes = convertToMinutes(beginningMeeting); | ||
|
||
let reverseString = ''; | ||
for (let i = formattedString.length - 1; i >= 0; i--) { | ||
reverseString += formattedString[i]; | ||
} | ||
return reverseString === formattedString; | ||
} | ||
const isMeetingAfterWorkStart = startWorkingDayInMinutes <= beginningMeetingInMinutes; | ||
const isMeetingBeforeWorkEnd = (beginningMeetingInMinutes + durationMeeting) <= endWorkingDayInMinutes; | ||
|
||
//Задача №3. Извлечение цифр из строк. | ||
function parseToPositiveInt(string) { | ||
const stringForloop = string.toString(); | ||
return isMeetingAfterWorkStart && isMeetingBeforeWorkEnd; | ||
} | ||
|
||
let formattedString = ''; | ||
for (let i = 0; i < stringForloop.length; i++) { | ||
if (!isNaN(parseInt(stringForloop[i], 10))) { | ||
formattedString += stringForloop[i]; | ||
} | ||
} | ||
function convertToMinutes(inputValue) { | ||
const [hours, minutes] = inputValue.split(':'); | ||
|
||
return formattedString !== '' ? +formattedString : NaN; | ||
return (Number(hours) * 60) + Number(minutes); | ||
} | ||
|
||
console.log(checkMeetingTimeframe('08:00', '17:30', '14:00', 90)); | ||
console.log(checkMeetingTimeframe('8:0', '10:0', '8:0', 120)); | ||
console.log(checkMeetingTimeframe('08:00', '14:30', '14:00', 90)); | ||
console.log(checkMeetingTimeframe('14:00', '17:30', '08:0', 90)); | ||
console.log(checkMeetingTimeframe('8:00', '17:30', '08:00', 900)); | ||
Check failure on line 24 in js/functions.js GitHub Actions / Check
|