Skip to content

Instantly share code, notes, and snippets.

@damdafayton
Last active September 2, 2022 06:42
Show Gist options
  • Save damdafayton/409d955d2f9d6f7c989f5686001f8c32 to your computer and use it in GitHub Desktop.
Save damdafayton/409d955d2f9d6f7c989f5686001f8c32 to your computer and use it in GitHub Desktop.
Akbank Web3 Practicum
function sumOddOrEven(num){
return num.toString().split('').reduce((prev,cur)=> parseInt(prev, 10) + parseInt(cur, 10)) % 2 === 0 ? 'Even' : 'Odd'
}
@damdafayton
Copy link
Author

Bir sayının Tek mi Çift mi olduğunu belirleyen bir işlev oluşturun. Bir sayı, tüm basamaklarının toplamı tek ise tek, tüm basamaklarının toplamı çift ise bir sayıdır. Bir sayı tek ise, "Odd" döndürün. Aksi takdirde, "Even" değerini döndürün. Örnek olarak:

oddishOrEvenish(43) ➞ "Odd"
// 4 + 3 = 7
// 7 % 2 = 1

oddishOrEvenish(373) ➞ "Odd"
// 3 + 7 + 3 = 13
// 13 % 2 = 1

oddishOrEvenish(4433) ➞ "Even"
// 4 + 4 + 3 + 3 = 14
// 14 % 2 = 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment