Skip to content

Commit 858b891

Browse files
committed
collect repeated numbers
1 parent 501119d commit 858b891

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

Diff for: duplicated-numbers.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const numbers = [1, 2, 3, 1, 2, 3, 1, 2, 2, 1, 3, 5, 76, 8, 5, 4, 3, 5, 65, 43, 43, 54, 4, 4, 53, 345];
2+
3+
function detectRepeatedNumbersAndCollect(array: number[]): number[] {
4+
let repeatedNumbers: number[] = [];
5+
6+
for (let i = 0; i < array.length; i++) {
7+
for (let j = i + 1; j < array.length; j++) {
8+
if (array[i] === array[j]) {
9+
console.log(`Eşleşme sağlandı: j: ${array[j]} i : ${array[i]}`);
10+
}
11+
if (array[i] === array[j] && !repeatedNumbers.includes(array[i])) {
12+
repeatedNumbers.push(array[i]);
13+
}
14+
}
15+
}
16+
17+
return repeatedNumbers;
18+
}
19+
20+
console.log(detectRepeatedNumbersAndCollect(numbers));

Diff for: even-or-odd renamed to even-or-odd.js

File renamed without changes.

Diff for: exes-and-ohs.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
function XO(str =[]) {
2-
let amount_x = [],amount_o = [];
3-
for(let i of str.toString()) {
4-
if(i.toLocaleLowerCase() == 'x') {
5-
amount_x.push(i)
6-
}
7-
if(i.toLocaleLowerCase() == 'o') {
8-
amount_o.push(i)
9-
}
1+
function XO(str = []) {
2+
let amount_x = [],
3+
amount_o = [];
4+
for (let i of str.toString()) {
5+
if (i.toLocaleLowerCase() == "x") {
6+
amount_x.push(i);
107
}
11-
return amount_o.length === amount_x.length ? true:false;
8+
if (i.toLocaleLowerCase() == "o") {
9+
amount_o.push(i);
10+
}
11+
}
12+
return amount_o.length === amount_x.length ? true : false;
1213
}
1314

14-
console.log(XO("ooxXm"))
15-
console.log(XO("zpzpzpp"))
16-
console.log(XO("zzoo"))
15+
console.log(XO("ooxXm"));
16+
console.log(XO("zpzpzpp"));
17+
console.log(XO("zzoo"));

0 commit comments

Comments
 (0)