Değerlerden herhangi biri özellikle eşleşiyorsa, bir nesnenin aynı özelliğini, doğru dönen değerlerin bir listesiyle karşılaştırmam gereken senaryolar için standart/en iyi bir uygulama arıyorum. Bir mülke karşı birden çok değeri karşılaştırıp doğru bir şekilde döndürmenin daha iyi bir yoluna ihtiyacınız var;
Şu kodif (object.property == "string1"
|| object.property == "string2"
|| object.property == "string3"
|| object.property == "string4"
|| object.property == "string5"
|| object.property == "string6"
|| object.property == "string7"
|| object.property == "string8"
|| object.property == "string9"
|| object.property == "string10"
|| object.property == "string11"
|| object.property == "string12"
|| object.property == "string13"
|| object.property == "string14"
|| object.property == "string15")
- anahtar kutusu tasarımını kullanmaktan –
Tüm geçerli cevaplar ve sağladığımdan çok daha güzel. İyi iş beyler. Andrew'a oy vereceğim çünkü en okunaklı gibi görünüyor ve bir dizi dizisi kullandığından en az miktarda bellek ayırmalı. Yine harika cevaplar için çok teşekkürler. – TXRAckAck