Salaamun Alaikum,
We find this narration: One day another Jewish person came to Imam Ali (A.S.). He was planning to ask Imam Ali (A.S.) such a question, which would take Imam Ali (A.S.) a long time to answer and because of that his Maghrib Prayers would be delayed.
He asked, "Imam Ali you say you know everything in the world, then tell me which animals lay eggs and which animals give birth to their young ones."
Imam Ali (A.S.) looked back at him, smiled and said, "The animals who have their 'EARS' outside their body give birth to their young ones and the animals who have their 'EARS' inside their body lay eggs."
However, we get to see on internet some snakes who have ears inside give birth not eggs. It is further learnt through internet that, snakes that give birth to live young are called viviparous snakes. It turns out that the eggs of viviparous snakes are pretty much like those of egg-laying snakes (the technical term for egg-layers is oviparous). Viviparous snake eggs don't have an external shell, but the embryos are contained within a membrane. Oviparous snake eggs also have membranes, but they're inside the shell. So, in other words, viviparous snakes have "lost" their shell, in an evolutionary sense. Upon "birth" (or parturition, if you want to be technical about it), the snake embryos burst the membrane and exit the female - so they're basically just hatching inside their mother and leaving.
However, to reconcile the aforesaid, kindly inform us about the following:
1) The source of the aforesaid hadith.
2) The correct translation of aforesaid hadith and whether the hadith refers to animals or it refers to reptiles or it refers to mammal or any other living beings.
3) Reconciliation between hadith and scientific facts.
Jazakallah, Was-salaam.

Salam un ‘Alaikum,
In well-known hadith sources we found no trace of the first part of the hadith you had referred to. But Ibn Qutaybih Dinwari’s Uyun al-Akhbar has quoted the second part of the Tradition, which is a statement Imam ‘Ali ibn Abi Talib, the Commander of the Faithful (p.b.u.h.) has made on differentiation between oviparous and viviparous animals. Dinwari writes:
حدّثني الرياشيّ قال: ليس شي‏ء يغيب‏ أذناه‏ إلا و هو يبيض؛ و ليس شي‏ء يظهر أذناه إلا و هو يلد، و روى ذلك عن عليّ بن أبي طالب عليه السلام. (1)
Al-Riyashi told me: “Any animal whose ears are not visible lays eggs, and any animal with visible ears gives birth to young ones”. This has been narrated from ‘Ali ibn Abi Talib, the Commander of the Faithful, peace be upon him.
1) In explaining this hadith, Allamah Hasan Zadeh has said, “The Commander of the Faithful, Imam ‘Ali (p.b.u.h.), the Imam of all, has explained a mystery in the world of creation (2)
ليس شى‏ء تغيب‏ أذناه‏ إلّا و هو يبيض، و ليس شى‏ء تظهر أذناه إلّا و هو يلد.
“Any animal with ears that do not stick out lays eggs, and any animal with ears that stick out gives birth to young ones.”
Explanation:
“This means: the snake, the alligator, the fish, the eel, the turtle and most birds that are without the ear flaps and whose ears are not visible on their heads lay eggs. Humans, the deer, the horse, the camel, the lion, the bat, and most birds whose ears stick out give birth to the young ones’ “.
"Mention should be made of an eminent lady, indeed a seeker of knowledge, Umm Jabir, whose name has appeared on page 14 of the book Kashkool that Farhad Mirza, the Qajar scholar has written. She was fully resolved to solve this important matter.
"Farhad Mirza has quoted an event from the book Majlis, written by Amir Kamal al-Din Fanai, in this way: Imam Sadiq, peace be upon him, asked Umm Jabir, ‘What are you doing?’
She said, “I want to do a research to discover which animals lay eggs and which animals give birth to their young ones”.
The Imam (p.b.u.h.) said, “It is not necessary to give the matter so much thought. Write! Any animal whose ears stick out gives birth, and any animal whose ears are not visible lays eggs. ‘This is the ordaining of the All-mighty, the All-knowing’”.
More Examples:
The hawk lays eggs although it flies and has invisible ears. The turtle - a grazing animal - has similar ears; it lays eggs, but a bat has ears sticking out; it gives birth.
Shaykh al-Re’is Ibn Sina (Avicenna) has, at the beginning of an essay, the fifth animal - in his book, Shafa, has said,
ليس شى‏ء ممّا له رجلان يلد حيوانا إلّا الإنسان وحده.
“No biped animal gives birth [to young ones] except human beings”. This means that the biped also lay eggs, with the exception of humans. Only humans are viviparous. (3)
There is an exception to the case, it is the bat, which is a biped yet gives birth to the young. However, the criterion we quoted from the Imam (p.b.u.h.)’s statement is perfect.
Explanation with Regard to the Snakes:
a) A prevailing misunderstanding is that snakes make nests for the protection of the eggs. This applies to king Cobra snake only, not to all. It builds a nest to protect its young ones.
b) Not all snakes are oviparous. About 70 percent are. Some others give birth to their young ones, in a manner very similar to 30 percent of mammals. This is because of the climatic conditions; Certain types of snakes are not able to lay eggs. Snakes in cold climates, therefore, are viviparous.
2) Given this explanation, it can be said that snakes are generally oviparous. But sometimes the conditions are not favorable for laying the eggs outside. The snake keeps the egg in its womb until the young is ready to hatch. That is why it looks as if they are viviparous.