├── .gitattributes ├── Find Intersection Challange ├── findIntersection.js └── findIntersection2.js ├── First Reverse Challange └── firstReverse.js ├── FirstFactorial Challange └── firstFactorial.js ├── LetterCapitalize Challange ├── letterCapitalize.js └── letterCapitalize2.js ├── LetterChange Challange ├── letterChange.js └── letterChange2.js ├── LongestWord Challange └── longestWord.js ├── PrimeTime Challange └── primeTime.js ├── Question Marks Challange ├── questionMarks.js └── questionMarks2.js ├── Run Length Challange ├── runLength.js └── runLength2.js ├── UserValidation Challange └── userValidation.js ├── easy.js └── index.html /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Find Intersection Challange/findIntersection.js: -------------------------------------------------------------------------------- 1 | export const findIntersection = (strArr) => { 2 | // İlk adım olarak, strArr dizisini boşluk karakterine göre bölelim ve iki dizi elde edelim. 3 | const arr1 = strArr[0].split(", "); 4 | const arr2 = strArr[1].split(", "); 5 | 6 | // Ortak değerleri bulmak için bir döngü kullanalım. 7 | const intersection = []; 8 | 9 | for (let i = 0; i < arr1.length; i++) { 10 | for (let j = 0; j < arr2.length; j++) { 11 | if (arr1[i] === arr2[j]) { 12 | intersection.push(arr1[i]); 13 | break; // Ortak bir değer bulduğumuzda, bir sonraki değeri kontrol etmeye gerek yok. 14 | } 15 | } 16 | } 17 | 18 | // Eğer ortak değerler bulunmamışsa -1 döndürelim, aksi takdirde ortak değerleri virgülle birleştirip döndürelim. 19 | return intersection.length > 0 ? intersection.join(",") : -1; 20 | 21 | }; 22 | 23 | // Fonksiyonu test edelim: 24 | // console.log(findIntersection(["1, 3, 4, 7, 13", "1, 2, 4, 13, 15"])); // Sonucu "1,4,13" olarak döndürecek. 25 | // console.log(findIntersection(["1, 2, 3, 4, 5", "6, 7, 8, 9, 10"])); // Sonucu -1 olarak döndürecek. 26 | -------------------------------------------------------------------------------- /Find Intersection Challange/findIntersection2.js: -------------------------------------------------------------------------------- 1 | // bir diğer alternatif çözüm: 2 | 3 | export const findIntersection2 = (array) => { 4 | // 1. olarak yeni bir array tipinde değişken tanımlayalım 5 | let intersection = []; 6 | 7 | // 2. olarak split(), replace() 8 | const kume1 = array[0].replace(/\s/g, "").split(","); 9 | const kume2 = array[1].replace(/\s/g, "").split(","); 10 | 11 | // 3. olarak forEach() kullanarak bütün array içerisindeki karakterlerin diğer array içerisinde olup olmadığını kontrol edicez. Varsa tanımladığımız yeni array değişkeni içerisine bu değeri koyucaz 12 | 13 | kume2.forEach((item) => { 14 | if (kume1.includes(item)) { 15 | intersection.push(item); 16 | } 17 | }); 18 | 19 | // 4. olarak tanımlamış olduğumuz array boşsa return false boş değilse de arry içindeki değerleri string halinde döner 20 | 21 | if (intersection.length != 0) { 22 | return intersection.toString(); 23 | } else { 24 | return false; 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /First Reverse Challange/firstReverse.js: -------------------------------------------------------------------------------- 1 | export const firstReverse = (str) => { 2 | const array = str.split(""); 3 | const reverseArray = array.reverse(); 4 | const newStr = reverseArray.join(""); 5 | 6 | return newStr; 7 | 8 | // return str.split("").reverse().join("") ==> kısa çözüm 9 | }; 10 | 11 | // Bu kod, firstReverse adlı bir işlev tanımlar. Bu işlev, bir dizeyi ters çevirmek için split, reverse ve join dizge yöntemlerini kullanır. İşte bu işlemlerin adımları: 12 | 13 | // str.split(''): İlk olarak, gelen dizeyi karakter dizgesi (string) içindeki her karakteri ayırmak için split('') kullanır. Bu, her karakteri bir diziye ayırır. 14 | 15 | // reverse(): Ardından, bu oluşturulan diziyi tersine çevirmek için reverse() yöntemini kullanır. Bu, diziyi ters sıraya dizer. 16 | 17 | // join(''): Son olarak, ters çevrilmiş karakterleri tekrar birleştirmek için join('') kullanır. Bu, karakter dizisini birleştirip tersine çevrilmiş dizgeyi oluşturur. 18 | -------------------------------------------------------------------------------- /FirstFactorial Challange/firstFactorial.js: -------------------------------------------------------------------------------- 1 | export const firstFactorial = (num) => { 2 | let factorial = 1; 3 | 4 | for (let i = 2; i <= num; i++) { 5 | factorial *= i; 6 | } 7 | 8 | return factorial; 9 | }; 10 | 11 | /* 12 | First Factorial 13 | 14 | Using the JavaScript language, have the function FirstFactorial(num) 15 | take the num parameter being passed and return the factorial of it (ie. 16 | if num = 4, return (4 * 3 * 2 * 1)). For the test cases, the range 17 | will be between 1 and 18. 18 | */ 19 | -------------------------------------------------------------------------------- /LetterCapitalize Challange/letterCapitalize.js: -------------------------------------------------------------------------------- 1 | export const letterCapitalize = (str) => { 2 | let newString = []; 3 | str.split(" ").forEach((word) => { 4 | newString.push(word.charAt(0).toUpperCase() + word.slice(1, word.length)); 5 | }); 6 | 7 | return newString.join(" "); 8 | }; 9 | 10 | // Soruda istenen; verilen bir string içerisindeki kelimelerin sadece ilk harflerinin büyütülmesi ve cümleyi bu şekilde return etmem gerek. Ayrıca soruda string oluşturan kelimeler arasında sadece 1 adet boşluk olacaSoruyu çözerken izlediğim adımlar; 11 | // 1 - String'i split metodu kullanarak bir array haline dnüştür ve tanımlanmış olan bir değişkene ata. 12 | // 2 -Array tipinde boş bir değişken tanımla, 13 | // 3 - split() metodu bir array döner. Bu yüzden array içerisinde sırayla gezinebilmemiz için forEach metodu uygula, 14 | // 4 - forEach metodu ile beraber array içerisindeki her kelime üzerinde sırasıyla charAt(), toUpperCase() ve slice() metodlarını uygulayarak, kelimenin önce ilk harfini büyüt sonra ise slice ile 1. index'ten itibaren oluşturulmuş kelimenin geri kalanı ile '+' operator kullanarak birleştir ve ilk başta tanımlanmış olan array tipindeki değişkene push() et. 15 | // 5 - İçi ilk harfleri büyütülmüş kelimelerle doldurulmuş olan array'i join metodu kullanarak aralarında bir adet boşluk kalacak şekilde string'e çevir ve bu string'i de return et. 16 | -------------------------------------------------------------------------------- /LetterCapitalize Challange/letterCapitalize2.js: -------------------------------------------------------------------------------- 1 | function capitalizeSentence(sentence) { 2 | const words = sentence.split(" "); // Cümleyi boşluklara göre ayırdım 3 | const capitalizedWords = words.map( 4 | (word) => word.charAt(0).toUpperCase() + word.slice(1) 5 | ); // Her kelimenin ilk harfini büyüttüm 6 | const result = capitalizedWords.join(" "); // Büyütülmüş kelimeleri birleştirdim ve boşlukla ayırdım 7 | 8 | return result; 9 | } 10 | 11 | const exampleSentence = "merhaba dünya! javascript çok eğlenceli"; 12 | const result = capitalizeSentence(exampleSentence); 13 | console.log(result); 14 | -------------------------------------------------------------------------------- /LetterChange Challange/letterChange.js: -------------------------------------------------------------------------------- 1 | export const letterChange = (str) =>{ 2 | 3 | 4 | // 1. aşama: js charcode ve charcodeAt metotlarını kullanacağım için ilk önce 5 | // string içerisindeki harfleri toLowerCase metodu ile küçük harfe çeviririz. 6 | let newString = str.toLowerCase().replace(/[a-z]/gi, (char) => { 7 | if (char === "z") { 8 | return "a"; 9 | } else { 10 | return String.fromCharCode(char.charCodeAt() + 1); 11 | } 12 | }); 13 | 14 | // 2. aşama: replace metodu ile harfleri tarıyoruz ve ilk olarak eğer z varsa 15 | // bu değeri hemen a ile değiştiriyoruz. Eğer harfimiz z değilse String.fromCharCode 16 | // ve char.charcodeAt() kullanarak alfabedeki bir sonraki harf ile bu değeri değiştiriyoruz. 17 | 18 | let vowelCapitalize = newString.replace(/a|e|i|o|u/gi, (char) => 19 | char.toUpperCase() 20 | ); 21 | 22 | return vowelCapitalize; 23 | } 24 | 25 | 26 | // Letter Changes 27 | // JavaScript dilini kullanarak, LetterChanges fonksiyonunu yazın. Bu fonksiyon, verilen 28 | // str parametresini alacak ve aşağıdaki algoritmayı kullanarak değiştirecek. Her bir 29 | // harfi, alfabedeki sıradaki harfle değiştirin (örneğin c, d olur, z, a olur). Daha 30 | // sonra bu yeni string içindeki her sesli harfi (a, e, i, o, u) büyük harfe çevirin 31 | // ve nihayetinde bu değiştirilmiş string'i döndürün. 32 | -------------------------------------------------------------------------------- /LetterChange Challange/letterChange2.js: -------------------------------------------------------------------------------- 1 | function LetterChanges(str) { 2 | // Fonksiyonun başında kullanılacak değişkenleri tanımlayalım 3 | let result = ""; 4 | let vowels = "aeiou"; 5 | 6 | // String üzerinde dönerek her bir karakteri işleyelim 7 | for (let i = 0; i < str.length; i++) { 8 | let char = str[i]; 9 | 10 | // Eğer karakter bir harf ise işleme başlayalım 11 | if (char.match(/[a-z]/i)) { 12 | // Harfin ASCII kodunu alalım 13 | let charCode = char.charCodeAt(0); 14 | 15 | // Eğer harf z ise a'ya dönelim, aksi takdirde bir sonraki harfe geçelim 16 | char = charCode === 122 ? "a" : String.fromCharCode(charCode + 1); 17 | 18 | // Eğer yeni harf bir sesli harf ise büyük harfe çevirelim 19 | if (vowels.includes(char)) { 20 | char = char.toUpperCase(); 21 | } 22 | } 23 | 24 | // Sonuç string'ine karakteri ekleyelim 25 | result += char; 26 | } 27 | 28 | return result; 29 | } 30 | 31 | console.log(LetterChanges("Hello World")); 32 | -------------------------------------------------------------------------------- /LongestWord Challange/longestWord.js: -------------------------------------------------------------------------------- 1 | export const longestWord = (str) => { 2 | const array = str.replace(/[^a-zA-Z]/g, "").split(" "); 3 | array.sort((a, b) => { 4 | return b.length - a.length; 5 | }); 6 | return array[0]; 7 | 8 | // 1. adım: noktalama işaretlerini kaldır: 9 | // 2. adım: cümleyi boşluklardan bölüp, kelimelerle bir array oluştur 10 | // 3. adım: kelimelerle oluşturduğumuz arrayi, kelimelerin karakter sayılarına göre azalan bir şekilde sıralamak 11 | // 4. adım: en başta yani 0. indekste yer alan kelimeyi return etmek 12 | }; 13 | 14 | /* 15 | Longest Word 16 | 17 | - Using the JavaScript language, have the function LongestWord(str) take the str 18 | parameter being passed and return the largest word in the string. 19 | 20 | - If there are two or more words that are the same length, return the first word 21 | from the string with that lenght. 22 | 23 | - Ignore punctuation and assume str will not be empty. 24 | 25 | */ 26 | -------------------------------------------------------------------------------- /PrimeTime Challange/primeTime.js: -------------------------------------------------------------------------------- 1 | export const primeTime = (num) => { 2 | if (num <= 1) return false; 3 | if (num === 2) return true; 4 | if (num > Math.pow(num, 16)) return false; 5 | 6 | let isPrime = true; 7 | for (let i = 2; i < Math.ceil(num / 2); i++) { 8 | if (num % i === 0) isPrime = false; 9 | } 10 | return isPrime; 11 | }; 12 | 13 | /* 14 | For this challange you will be determining if an argument is a prime number. Have the function PrimeTime(num) take the num parameter being passed and return the string true if the parameter is a prime number, otherwise return the string false. The range will be between 1 and 2^16. 15 | */ 16 | -------------------------------------------------------------------------------- /Question Marks Challange/questionMarks.js: -------------------------------------------------------------------------------- 1 | export const questionMark = (str) => { 2 | // 1. olarak str >= 5 kontrol edelim 3 | 4 | if (str.length < 5) { 5 | return false; 6 | } 7 | 8 | // 2. olarak ? işareti ve rakam olmayan tüm değerleri temizeyelim 9 | 10 | const newStr = str.replace(/[^0-9?]/g, ""); 11 | 12 | // 3. olarak forEach için string -> array'a çevir 13 | 14 | const arr = newStr.split(""); 15 | 16 | // 4. olarak forEach içerisinde kullanılacak değişkenleri (sums, sum, iterator) tanımlanması 17 | 18 | let sums = []; 19 | let sum = 0; 20 | let iterator = 0; 21 | 22 | // 5. olarak forEach döngüsü ile her bir rakam ve kendisinden sonraki 4. karakterin toplanarak sum değişkenine eşitlenmesi ve sonrada bu değerin sums array'ine eklenmesi 23 | 24 | arr.forEach((item) => { 25 | if (item != "?") { 26 | sum = parseInt(item) + parseInt(arr[iterator + 4]); 27 | sums.push(sum); 28 | } 29 | iterator += 1; 30 | }); 31 | 32 | console.log(str); 33 | console.log(newStr); 34 | console.log(sums); 35 | 36 | // 6. olarak sums array'i içerisinde 10 değeri varsa true, yoksa false değerin dönülmesi 37 | 38 | return sums.includes(10) ? true : false; 39 | }; 40 | 41 | // Verilen bir karakter dizisinde herhangi iki rakam arasında tam olarak üç soru işareti ("?") olup olmadığını kontrol etmek. 42 | // Eğer bu koşul sağlanıyorsa, bu iki rakam arasındaki rakamların toplamının 10 olduğunu da kontrol etmek. 43 | // Bu koşulların tümü sağlanıyorsa, sonuç "true" olmalı, aksi takdirde "false" olmalı. 44 | -------------------------------------------------------------------------------- /Question Marks Challange/questionMarks2.js: -------------------------------------------------------------------------------- 1 | // bir diğer alternatif çözüm: 2 | 3 | export const questionMark2 = (str) => { 4 | // Bu işlemde kullanacağımız iki sayıyı ve toplamı sıfırla 5 | let num1 = 0; 6 | let num2 = 0; 7 | let sum = 0; 8 | 9 | // Dizeyi dolaş 10 | for (let i = 0; i < str.length; i++) { 11 | const char = str[i]; 12 | 13 | // Eğer karakter bir rakam ise 14 | if (!isNaN(char)) { 15 | // Eğer num2 0 ise, num1'i güncelle 16 | if (num2 === 0) { 17 | num1 = parseInt(char); 18 | } else { 19 | // Eğer num2 zaten dolu ise, num1 ve num2'yi güncelle ve toplamı hesapla 20 | num1 = num2; 21 | num2 = parseInt(char); 22 | sum = num1 + num2; 23 | 24 | // Eğer toplam 10 ise ve arada 3 soru işareti varsa, true dön 25 | if (sum === 10 && str.slice(i - 4, i).includes("???")) { 26 | return true; 27 | } 28 | } 29 | } 30 | } 31 | 32 | // Eğer hiçbir eşleşme yoksa, false dön 33 | return false; 34 | }; 35 | 36 | // Örnek kullanım 37 | console.log(questionMark2("acc?7??sss?3rr1??????5")); // true 38 | console.log(questionMark2("aa6?9")); // false 39 | -------------------------------------------------------------------------------- /Run Length Challange/runLength.js: -------------------------------------------------------------------------------- 1 | export const runLength = (str) => { 2 | let object = {}; 3 | let newString = ""; 4 | 5 | for (let i = 0; i < str.length; i++) { 6 | str[i] in object 7 | ? (object[str[i]] = object[str[i]] + 1) 8 | : (object[str[i]] = 1); 9 | } 10 | 11 | for (let i = 0; i < Object.keys(object).length; i++) { 12 | newString += Object.values(object)[i]; 13 | newString += Object.keys(object)[i]; 14 | } 15 | 16 | return newString; 17 | }; 18 | 19 | /* 20 | For this challange you will determine the Run Length Encoding of a string. Have the function RunLength(str) 21 | take the str parameter being passed and return a compressed version of the string using the Run-Length encoding 22 | algortihm. This algorithm works by taking the occurrance of each repeating character and outputting that number 23 | along with a single character of the repeating sequence. 24 | 25 | For example : "wwwggopp" would return 3w2g1o2p. The string will not contain any numbers, punctuation, or symbols. 26 | 27 | */ 28 | -------------------------------------------------------------------------------- /Run Length Challange/runLength2.js: -------------------------------------------------------------------------------- 1 | function RunLength(str) { 2 | let result = ""; 3 | let count = 1; 4 | 5 | for (let i = 0; i < str.length; i++) { 6 | if (str[i] === str[i + 1]) { 7 | count++; 8 | } else { 9 | result += count + str[i]; 10 | count = 1; 11 | } 12 | } 13 | 14 | return result; 15 | } 16 | 17 | const encodedString = RunLength("wwwggopp"); 18 | console.log(encodedString); 19 | -------------------------------------------------------------------------------- /UserValidation Challange/userValidation.js: -------------------------------------------------------------------------------- 1 | export const userValidation = (str) => { 2 | if ( 3 | str.length >= 4 && 4 | str.length <= 25 && 5 | /[a-zA-Z]/.test(str.slice(0, 1)) && //str.charAt(0) 6 | /^\w+$/.test(str) && 7 | /[a-zA-Z0-9]/.test(str.slice(-1)) //str.charAt(str.length-1) 8 | ) { 9 | return true; 10 | } else { 11 | return false; 12 | } 13 | }; 14 | 15 | /* Rules: 16 | 1. The username is between 4 and 25 characters. 17 | 2. It must start with a letter. 18 | 3. It can only cotain letters, numbers, and the underscore character. 19 | 4. It cannot end with an underscore character. 20 | 21 | If the username is valid then your program should return the string true. 22 | 23 | Example: 24 | u_hello_world123 25 | */ 26 | -------------------------------------------------------------------------------- /easy.js: -------------------------------------------------------------------------------- 1 | import { userValidation } from "./UserValidation Challange/userValidation.js"; 2 | import { longestWord } from "./LongestWord Challange/longestWord.js"; 3 | import { firstFactorial } from "./FirstFactorial Challange/firstFactorial.js"; 4 | import { firstReverse } from "./First Reverse Challange/firstReverse.js"; 5 | import { findIntersection } from "./Find Intersection Challange/findIntersection.js"; 6 | import { findIntersection2 } from "./Find Intersection Challange/findIntersection2.js"; 7 | import { questionMark2 } from "./Question Marks Challange/questionMarks2.js"; 8 | import { letterCapitalize } from "./LetterCapitalize Challange/letterCapitalize.js"; 9 | import { letterChange } from "./LetterChange Challange/letterChange.js"; 10 | import { primeTime } from "./PrimeTime Challange/primeTime.js"; 11 | import { runLength } from "./Run Length Challange/runLength.js"; 12 | 13 | // console.log(userValidation("u_hello_world123")); 14 | // console.log(longestWord("fun&!! time")); 15 | // console.log(firstFactorial(8)); 16 | // console.log(firstReverse("merhaba")); 17 | // console.log(findIntersection(["1, 3, 4, 7, 13", "1, 2, 4, 13, 15"])); // Sonucu "1,4,13" olarak döndürecek. 18 | // console.log(findIntersection(["1, 2, 3, 4, 5", "6, 7, 8, 9, 10"])); // Sonucu -1 olarak döndürecek. 19 | // console.log(findIntersection2(["1, 3, 9, 10, 17, 18", "1, 4, 9, 10"])); 20 | // console.log(questionMark2("acc?7??sss?3rr1??????5")); 21 | 22 | // console.log(letterCapitalize("bugün önce kodlama çalıştım, ardından spor yaptım, daha sonra ise bilgisayar oyunu oynadım.")); 23 | // console.log(letterChange("Hello")); 24 | 25 | // console.log(primeTime(41332)); 26 | 27 | console.log(runLength("wwwwggggoooyyypp")); 28 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | 11 | 12 | --------------------------------------------------------------------------------