My background is primarily in C#. Though, I've gotten comfortable with JavaScript, I feel that stylewise my JS code looks more like C# code.
Does the following code's style conform to "standard JS style"?
processArray = (myArray) => {
if(typeof myArray === "undefined" || myArray == null || myArray.length == 0)
return null;
let animals = [];
let animal = {};
for(let item of myArray) {
animal = getAnimal(item);
if(item !== null)
animals.push(animal);
};
return animals;
}
getAnimal = (data) => {
if(typeof data === "undefined" || data == null)
return null;
const animal = {
id: data.id,
type: data.type,
name: data.name
};
return animal;
}
It's important to note that I'm not so much talking about formatting such as indentations, opening curly braces on the same line as the function name, etc.
What I'm really talking about is the way the code is structured. For example, as an "old school" C# developer, I like creating variables and assigning my data to them and cleanly returning them in my methods.
I see that a lot of JS developers chain one function to another or use a lot of callbacks. In other words, I see a lot of intermingling of functions. I think C# has also borrowed a few patterns from JS but for the most part, the coding style I used here is pretty typical "old school" C#.
Maybe an analogy will help clarify what I'm talking about. It's like a person whose native language is German/Italian/Japanase/etc. speaking English with an accent. Even if the grammar and even choice of words are perfect, the accent always gives it away.
So, I'm trying to understand if I'm writing JS code with a C# accent :-)