This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function charCount(str) { | |
| if (typeof str != "string") return; | |
| str = str.toLowerCase() | |
| const result = {} | |
| str.split("").forEach(char => { | |
| if ((/[a-z0-9]/).test(char)) { | |
| result[char]=result.hasOwnProperty(char) ? ++result[char] : 1 | |
| } | |
| }); | |
| return result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function validAnagram(str1, str2) { | |
| if (typeof str1 != "string" || typeof str2 != "string") return false; | |
| if (str1.length != str2.length) return false; | |
| [str1, str2] = [str1.toLocaleLowerCase(), str2.toLocaleLowerCase()] | |
| let frequencyStr1 = {} | |
| let frequencyStr2 = {} | |
| for (let char of str1) { | |
| frequencyStr1[char] = (frequencyStr1[char] || 0) + 1 | |
| } | |
| for (let char of str2) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function factorial(num) { | |
| if (num === 1) return 1; | |
| return num * factorial(num - 1); | |
| } | |
| //factorial(5) 120 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const cities = [ | |
| 'Adana', 'Adıyaman', 'Afyon', 'Ağrı', 'Amasya', 'Ankara', 'Antalya', 'Artvin', | |
| 'Aydın', 'Balıkesir', 'Bilecik', 'Bingöl', 'Bitlis', 'Bolu', 'Burdur', 'Bursa', 'Çanakkale', | |
| 'Çankırı', 'Çorum', 'Denizli', 'Diyarbakır', 'Edirne', 'Elazığ', 'Erzincan', 'Erzurum', 'Eskişehir', | |
| 'Gaziantep', 'Giresun', 'Gümüşhane', 'Hakkari', 'Hatay', 'Isparta', 'Mersin', 'İstanbul', 'İzmir', | |
| 'Kars', 'Kastamonu', 'Kayseri', 'Kırklareli', 'Kırşehir', 'Kocaeli', 'Konya', 'Kütahya', 'Malatya', | |
| 'Manisa', 'Kahramanmaraş', 'Mardin', 'Muğla', 'Muş', 'Nevşehir', 'Niğde', 'Ordu', 'Rize', 'Sakarya', | |
| 'Samsun', 'Siirt', 'Sinop', 'Sivas', 'Tekirdağ', 'Tokat', 'Trabzon', 'Tunceli', 'Şanlıurfa', 'Uşak', | |
| 'Van', 'Yozgat', 'Zonguldak', 'Aksaray', 'Bayburt', 'Karaman', 'Kırıkkale', 'Batman', 'Şırnak', | |
| 'Bartın', 'Ardahan', 'Iğdır', 'Yalova', 'Karabük', 'Kilis', 'Osmaniye', 'Düzce' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function validateFullName(name="") { | |
| const regex= /^[A-Za-zşŞıİçÇöÖüÜĞğ ]+$/; | |
| const fullName=String(name).trim() | |
| let warning={ | |
| status:true, | |
| message: "" | |
| }; | |
| if (fullName.length==0) { | |
| warning={ | |
| status:false, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function countUniqueValues(array){ | |
| if(array.length==0)return 0; | |
| let i=0; | |
| for (let j = 1; j < array.length; j++) { | |
| if(array[i]!=array[j]){ | |
| i++; | |
| array[i]=array[j]; | |
| } | |
| } | |
| return i+1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function search(array, val) { | |
| let min = 0; | |
| let max = array.length - 1; | |
| while (min <= max) { | |
| let middle = Math.floor((min + max) / 2); | |
| let currentElement = array[middle]; | |
| if (array[middle] < val) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function search(text,searchText){ | |
| text=text.toLowerCase(); | |
| searchText=searchText.toLowerCase(); | |
| let count=0; | |
| for (let i = 0; i < text.length; i++) { | |
| if(text.substr(i,searchText.length)==searchText){ | |
| count++; | |
| } | |
| } | |
| return count; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function bubbleSort(array) { | |
| let noSwaps; | |
| for (let i = array.length; i > 0; i--) { | |
| noSwaps = true; | |
| for (let j = 0; j < i - 1; j++) { | |
| if (array[j] > array[j + 1]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function selectionSort(array) { | |
| for (let i = 0; i < array.length; i++) { | |
| let lowestIndex = i | |
| for (let j = i + 1; j < array.length; j++) { | |
| if (array[lowestIndex] > array[j]) { | |
| lowestIndex = j; | |
| } |
OlderNewer