-
Notifications
You must be signed in to change notification settings - Fork 0
add hw7 task 1-2 #7
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?
Changes from all commits
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,26 @@ | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| const competitorPizzas = ['Peperoni', 'Caprichosa', 'Diablo', '4 cheeses', 'hawai'] | ||||||||||||||
| const myPizzas = ['peperoni', 'Caprichosa', 'Diablo', '4 cheeses'] | ||||||||||||||
|
|
||||||||||||||
| const pizzaResult = [] | ||||||||||||||
|
|
||||||||||||||
| for (let i = 0; i < competitorPizzas.length; i++) { | ||||||||||||||
| competitorPizzas[i] = competitorPizzas[i].toLowerCase() | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| for (let i = 0; i < myPizzas.length; i++) { | ||||||||||||||
| myPizzas[i] = myPizzas[i].toLowerCase() | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| for (const pizza of myPizzas) { | ||||||||||||||
| if (!competitorPizzas.includes(pizza)) { | ||||||||||||||
| pizzaResult.push(pizza) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if (pizzaResult.length === 0) { | ||||||||||||||
| console.log(null) | ||||||||||||||
| } else { | ||||||||||||||
| console.log(pizzaResult) | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+22
to
+26
Collaborator
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.
Suggested change
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
|
|
||
| // function showArgs(...arguments) { | ||
| // const result = [] | ||
| // for (const arg of arguments){ | ||
| // result.push(...arg) | ||
| // } | ||
| // console.log(result) | ||
| // } | ||
|
|
||
| // showArgs([1, 2],[3, 4], [5, 6]) | ||
|
|
||
| function derive(text) { | ||
|
Collaborator
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. Попробуй решить таким вариантом
По идее такой подход будет более прямолинейньім, убирая дополнимельньіе |
||
| let result = text.replaceAll(' ', '_') | ||
| let finalResult = '' | ||
|
|
||
| for (let i = 0; i < result.length; i++) { | ||
| if (result[i] === '_') { | ||
| finalResult += '_' | ||
| if (i + 1 < result.length) { | ||
| finalResult += result[i + 1].toUpperCase() | ||
| i++ | ||
| } | ||
| } else { | ||
| finalResult += result[i] | ||
| } | ||
| } | ||
|
|
||
| return finalResult[0].toLowerCase() + finalResult.slice(1) | ||
| } | ||
|
Comment on lines
+12
to
+29
Collaborator
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. Это сильно:) а почему бы не использовать .split и после .join?) |
||
|
|
||
| console.log(derive('I am super Engineer')) | ||
|
|
||
|
|
||
| function fibonacci(n) { | ||
| if (n <= 1) return n; | ||
| return fibonacci(n - 1) + fibonacci(n - 2); | ||
| } | ||
|
|
||
| console.log(fibonacci(8)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,32 @@ | ||
| function isPalindrome(word) { | ||
|
|
||
|
|
||
| const competitorPizzas = ['Peperoni', 'Caprichosa', 'Diablo', '4 cheeses', 'hawai'] | ||
| const myPizzas = ['peperoni', 'Caprichosa', 'Diablo', '4 cheeses'] | ||
|
|
||
| const pizzaResult = [] | ||
|
|
||
| for (let i = 0; i < competitorPizzas.length; i++) { | ||
| competitorPizzas[i] = competitorPizzas[i].toLowerCase() | ||
| const normalizedWord = word.toLowerCase(); | ||
|
|
||
| const reversedWord = normalizedWord.split('').reverse().join(''); | ||
|
Collaborator
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. а вот это хорошо! |
||
|
|
||
| return normalizedWord === reversedWord; | ||
| } | ||
|
|
||
| for (let i = 0; i < myPizzas.length; i++) { | ||
| myPizzas[i] = myPizzas[i].toLowerCase() | ||
| } | ||
| console.log(isPalindrome('madam')) | ||
| console.log(isPalindrome('hello')) | ||
| console.log(isPalindrome('Racecar')) | ||
|
|
||
| function longestWords(sentence) { | ||
| const words = sentence.split(' ') | ||
| let maxLength = 0; | ||
| let longestWords = []; | ||
|
|
||
| for (const pizza of myPizzas) { | ||
| if (!competitorPizzas.includes(pizza)) { | ||
| pizzaResult.push(pizza) | ||
| for (const word of words) { | ||
| if (word.length > maxLength) { | ||
| maxLength = word.length | ||
| longestWords = [word] | ||
| } else if (word.length === maxLength) { | ||
| longestWords.push(word) | ||
| } | ||
| } | ||
|
|
||
| return longestWords; | ||
| } | ||
|
|
||
| if (pizzaResult.length === 0) { | ||
| console.log(null) | ||
| } else { | ||
| console.log(pizzaResult) | ||
| } | ||
| console.log(longestWords('I am super engineer and coder')) | ||
| console.log(longestWords('I love coding and programming and depgramming')) | ||
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.
по факту ты меняешь изначальные массивы, потому может и есть смысл создавать отдельные переменные под массивы пицц в нижнем регистре