Skip to content

Commit fc8fbdc

Browse files
homework_6 fixed
1 parent 1ed5490 commit fc8fbdc

File tree

1 file changed

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

1 file changed

+21
-12
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,15 @@ console.log(reverseEachWord('Hi my Name is', false));
396396

397397
function wordCounter(sentence) {
398398
let strToArr = sentence.split(' ');
399-
let obj = strToArr.reduce(function(newValue, elem, index, arr) {
399+
let obj = strToArr.reduce(function(newValue, elem) {
400400
let firstElem = elem;
401401
let counter = 0;
402-
strToArr.forEach(function(elem, index, arr) {
402+
// strToArr.forEach(function(elem) {
403403
if (firstElem === elem) {
404404
counter++;
405405
newValue[firstElem] = counter;
406406
};
407-
});
407+
// });
408408
return newValue;
409409
}, {});
410410
return obj;
@@ -472,15 +472,17 @@ console.log(createHashTags(listOfCompanys));
472472
// *
473473
// * */
474474

475-
// function uniqueElements(arr) {
476-
477-
// }
475+
function uniqueElements(arr) {
476+
return arr.filter(function(value, index, arr){
477+
return arr.indexOf(value) == index
478+
})
479+
}
478480

479481
// //
480-
// let notUniqArray = [1, 1, 2, 2, 2, 5, 10, 25, 30, 5, 1, 0, 22, 3, 10, 3];
482+
let notUniqArray = [1, 1, 2, 2, 2, 5, 10, 25, 30, 5, 1, 0, 22, 3, 10, 3];
481483
// //
482-
// console.log(uniqueElements(notUniqArray)); //1,2,5,10,25,30,0,22,3,
483-
// console.log(uniqueElements([1, 1, 2, 3, 3])); // 1,2,3
484+
console.log(uniqueElements(notUniqArray)); //1,2,5,10,25,30,0,22,3,
485+
console.log(uniqueElements([1, 1, 2, 3, 3])); // 1,2,3
484486

485487
// /*
486488
// *
@@ -491,12 +493,19 @@ console.log(createHashTags(listOfCompanys));
491493
// *
492494
// * */
493495

494-
function filter (arr, callback, thisArg) {
496+
function filter (arr, callback) {
495497
let results = [];
496498
for (let i = 0; i < arr.length; i = i + 1) {
497-
if (callback.call(thisArg, arr[i], i, arr)) {
499+
if (callback(arr[i])) {
498500
results.push(arr[i]);
499501
}
500502
}
501503
return results;
502-
};
504+
};
505+
506+
let nums = [1,2,3,4,5,6];
507+
let data = filter(nums, function(num){
508+
return num > 2;
509+
})
510+
511+
console.log(data)

0 commit comments

Comments
 (0)