Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions hw6Task2.js
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()
}
Comment on lines +8 to +14

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по факту ты меняешь изначальные массивы, потому может и есть смысл создавать отдельные переменные под массивы пицц в нижнем регистре


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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (pizzaResult.length === 0) {
console.log(null)
} else {
console.log(pizzaResult)
}
console.log(pizzaResult.length ? pizzaResult : null)

39 changes: 39 additions & 0 deletions hw7Task1.js
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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Попробуй решить таким вариантом

  • сплитуем аргумент по пробелам
  • итерируемся по получившемуся массиву с помощью мапа приводя первую букву к верхнему регистру, если необходимо
  • вьіполняем джоин

По идее такой подход будет более прямолинейньім, убирая дополнимельньіе if вьіражения и лишнии мутации стринги
И возможно будет такой случай, что на вход будет подана такая строка I aM suPer EngInEeR
Посмотри какой результат будет :)

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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))
44 changes: 25 additions & 19 deletions hw7Task2.js
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('');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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'))