Created
February 2, 2016 13:55
-
-
Save co3moz/056b9cfeebc67c8dc0e8 to your computer and use it in GitHub Desktop.
Sayıların sonuna 'ta ya da 'tan eklemek için geliştirilmiş işlemci dostu fonksiyon
This file contains 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
/** | |
* Adds extension to number | |
* @param a Number | |
* @param [n] default is "n" | |
* @returns {string} | |
* @example turkishExtension(40); // "40'tan" | |
* @example turkishExtension(40, ""); // "40'ta" | |
*/ | |
function turkishExtension(a, n) { | |
var lastDigit = 1 << Math.abs(a % 10); | |
var extraTag = ""; | |
if (lastDigit & 390) extraTag = "'de"; | |
else if (lastDigit & 56) extraTag = "'te"; | |
else if (lastDigit & 576) extraTag = "'da"; | |
else { | |
lastDigit = 1 << Math.abs(a % 100 / 10); | |
if (lastDigit & 420) extraTag = "'de"; | |
else if (lastDigit & 602)extraTag = "'da"; | |
else { | |
lastDigit = 1 << Math.abs(a % 1000 / 100); | |
if (lastDigit & 1) extraTag = "'de"; | |
else { | |
lastDigit = 1 << Math.abs(a % 10000 / 1000); | |
if (lastDigit & 1) extraTag = "'de"; | |
else extraTag = "'da"; | |
} | |
} | |
} | |
if (a == 0) extraTag = "'da"; | |
return a + extraTag + (n == undefined ? "n" : n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment