Skip to content

Commit 2600d2b

Browse files
committed
edited
1 parent 59c271e commit 2600d2b

File tree

1 file changed

+46
-45
lines changed

1 file changed

+46
-45
lines changed

solutions/solutons-test-5/index.html

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,27 @@ <h1>JavaScript Test: 5</h1>
4444
let result;
4545
switch (planet.toLowerCase()) {
4646
case 'sun':
47-
result = 274 * m ;
47+
result = 274 * m;
4848
break;
4949
case 'jupiter':
50-
result = 25 * m ;
50+
result = 25 * m;
5151
break;
5252
case 'earth':
53-
result = 9.79 * m ;
53+
result = 9.79 * m;
5454
break;
5555
case 'venus':
56-
result = 8.87 * m ;
56+
result = 8.87 * m;
5757
break;
5858
case 'mars':
59-
result = 3.7 * m ;
59+
result = 3.7 * m;
6060
break;
6161
case 'moon':
62-
result = 1.62 * m ;
62+
result = 1.62 * m;
6363
break;
6464
default:
65-
result = 'Not a valid input'
66-
};
67-
if (typeof result ==='number') return result.toFixed(2) + ' N';
65+
result = 'Not a valid input';
66+
}
67+
if (typeof result === 'number') return result.toFixed(2) + ' N';
6868
else result;
6969
};
7070

@@ -79,7 +79,7 @@ <h1>JavaScript Test: 5</h1>
7979
==========================================================================================================
8080
*/
8181
const sentence = `%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& @emp%o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!?`;
82-
const cleanText = (rawText) => rawText.replace(/[,;#%&@!$']/g, '');
82+
const cleanText = rawText => rawText.replace(/[,;#%&@!$']/g, '');
8383
console.log(cleanText(sentence));
8484
/*
8585
=============================== QUESTION 3 ===========================================================
@@ -92,7 +92,7 @@ <h1>JavaScript Test: 5</h1>
9292
let count = 0;
9393
const words = text.replace(/[,;#%&@!$'.?]/g, '').split(' ');
9494
for (const word of words) {
95-
if (word.length > 1) count++;
95+
if (word.length > 1) count++;
9696
}
9797

9898
return count;
@@ -218,10 +218,9 @@ <h1>JavaScript Test: 5</h1>
218218
count++;
219219
}
220220
}
221-
return { words: newWords, count}
221+
return { words: newWords, count };
222222
};
223223
console.log(countOnlyMainWords(sentence));
224-
225224

226225
/*
227226
=============================== QUESTION 6 =================================================================
@@ -277,7 +276,7 @@ <h1>JavaScript Test: 5</h1>
277276
for (item of arr) {
278277
sum += item;
279278
}
280-
279+
281280
return Math.round(sum / arr.length);
282281
};
283282
const median = () => {
@@ -453,48 +452,50 @@ <h1>JavaScript Test: 5</h1>
453452
c. Do you think there is similarity between the speeches ?
454453
============================================================================================================
455454
*/
456-
const removeRepeatedWords = arr => {
455+
const removeRepeatedWords = arr => {
457456
const set = new Set(arr);
458457
return Array.from(set);
459458
};
460459

461-
const mostTenRepeatedWords = (words) => {
460+
const mostTenRepeatedWords = words => {
462461
const map = new Map();
463-
for (word of words) {
464-
if (!map.has(word)) {
465-
map.set(word, 1);
466-
} else {
467-
map.set(word, map.get(word) + 1);
468-
}
462+
for (word of words) {
463+
if (!map.has(word)) {
464+
map.set(word, 1);
465+
} else {
466+
map.set(word, map.get(word) + 1);
469467
}
468+
}
470469

471-
const sortItems = arr => {
472-
let sortedArray = [...arr];
473-
sortedArray.sort((a, b) => {
474-
if (a[1] > b[1]) {
475-
return -1;
476-
} else if (a[1] < b[1]) {
477-
return 1;
478-
} else {
479-
return 0;
480-
}
481-
});
482-
return sortedArray;
483-
};
484-
return sortItems(Array.from(map)).slice(0, 10)
485-
486-
}
487-
console.log(mostTenRepeatedWords(countOnlyMainWords(melina).words)) // melinas 10 most repeated words
488-
console.log(mostTenRepeatedWords(countOnlyMainWords(michelle).words)) // michelle's 10 most repeated words
470+
const sortItems = arr => {
471+
let sortedArray = [...arr];
472+
sortedArray.sort((a, b) => {
473+
if (a[1] > b[1]) {
474+
return -1;
475+
} else if (a[1] < b[1]) {
476+
return 1;
477+
} else {
478+
return 0;
479+
}
480+
});
481+
return sortedArray;
482+
};
483+
return sortItems(Array.from(map)).slice(0, 10);
484+
};
485+
console.log(mostTenRepeatedWords(countOnlyMainWords(melina).words)); // melinas 10 most repeated words
486+
console.log(mostTenRepeatedWords(countOnlyMainWords(michelle).words)); // michelle's 10 most repeated words
489487
// console.log(countOnlyMainWords(melina));
490488
// console.log(countOnlyMainWords(michelle));
491489

492-
493490
console.log(removeRepeatedWords(countOnlyMainWords(melina).words).sort());
494-
console.log(removeRepeatedWords(countOnlyMainWords(michelle).words).sort());
491+
console.log(
492+
removeRepeatedWords(countOnlyMainWords(michelle).words).sort()
493+
);
495494

496495
const melinaWords = removeRepeatedWords(countOnlyMainWords(melina).words);
497-
const michelleWords = removeRepeatedWords(countOnlyMainWords(michelle).words);
496+
const michelleWords = removeRepeatedWords(
497+
countOnlyMainWords(michelle).words
498+
);
498499

499500
// common words
500501
// check the similarity common words divided by their the total number of non repeated words
@@ -511,8 +512,8 @@ <h1>JavaScript Test: 5</h1>
511512
};
512513
console.log(checkSimilarity(michelleWords, melinaWords));
513514
const commonWords = checkSimilarity(michelleWords, melinaWords).length;
514-
console.log(Math.round(100 * commonWords / melinaWords.length)); // the similarity between the speech is so high
515-
console.log(Math.round(100* commonWords / michelleWords.length));
515+
console.log(Math.round((100 * commonWords) / melinaWords.length)); // the similarity between the speech is so high
516+
console.log(Math.round((100 * commonWords) / michelleWords.length));
516517
</script>
517518
</body>
518519
</html>

0 commit comments

Comments
 (0)