Skip to content

Commit 2af570a

Browse files
Balashov NikitaOlegLustenko
authored andcommitted
little fix, I try my best to use reduce but I can't understand it, I gonna ask you in the classroom about it
1 parent f78f1f6 commit 2af570a

File tree

1 file changed

+13
-12
lines changed
  • js-core/homeworks/homework-6/src

1 file changed

+13
-12
lines changed

js-core/homeworks/homework-6/src/main.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ function countLetterA(str) {
329329
let strTransformToArray = str.split('');
330330
strTransformToArray.forEach(function(value, index, arr) {
331331
if(value === 'a') {
332-
counterA += 1;
332+
return counterA += 1;
333333
}
334334
});
335335
return counterA;
@@ -375,8 +375,8 @@ console.log(reverseEachWord('The Document Object Model (DOM) is a programming in
375375
* переворачиваются в обратном порядке
376376
* */
377377

378-
function reverseEachWord2(str, boolean) {
379-
if(boolean === true) {
378+
function reverseEachWord2(str, shouldSentceBeReversed) {
379+
if(shouldSentceBeReversed === true) {
380380
let reverseStr = str.split(' ').reverse().join(' ');
381381
return reverseEachWord(reverseStr);
382382
} else {
@@ -469,30 +469,31 @@ console.log(createHashTags(listOfCompanys));
469469
* Выведите уникальные значения
470470
*
471471
* */
472-
472+
/*Solution 1*/
473473
function uniqueElements(arr) {
474474
let newArray = [];
475475
const sortArr = arr.sort(function(a, b) {
476476
if(a > b) return 1;
477+
if(a < b) return -1;
478+
});
479+
sortArr.filter(function(value, index, arr) {
480+
const nextValue = arr[index + 1];
481+
if(value < nextValue) {
482+
newArray.push(value);
483+
}
477484
});
478-
for(let i = 0; i < sortArr.length; i++) {
479-
const elem = sortArr[i];
480-
const nextElem = sortArr[i + 1];
481-
if(elem < nextElem) {
482-
newArray.push(elem);
483-
}
484-
}
485485
const lastElem = sortArr.pop();
486486
newArray.push(lastElem);
487487
return newArray;
488488
}
489489

490490
//
491-
let notUniqArray = [1, 1, 2, 2, 2, 5, 10, 25, 30, 5, 1, 0, 22, 3, 10, 3];
491+
let notUniqArray = [1, 1, 2, 2, 2, 5, 10, 25, 30, 5, 1, 0, 22, 3, 10, 3, 50, 50, 50, 12, 12, 12, 12, 8, 102, 102, 102];
492492
//
493493
console.log(uniqueElements(notUniqArray)); //1,2,5,10,25,30,0,22,3,
494494
console.log(uniqueElements([1, 1, 2, 3, 3])); // 1,2,3
495495

496+
496497
/*
497498
*
498499
* super2

0 commit comments

Comments
 (0)