Sorry for what is probably a silly question but it's bugging me...
int[] i = {3, 2, 1};
//why
Array.Sort(i);
//instead of
i.Sort();
char c = 'c';
//why
char.IsLetter(c);
//instead of
c.Isletter();
The slice() method creates a new array. The slice() method does not remove any elements from the source array.
Array.prototype.map() prototype. map() creates a new array by applying the provided transformation to each element of the original array. The result is an array with the same length as the original array and elements transformed based on the provided function.
In JavaScript, arrays have three static methods.
Thanks to Pedro d'Aquino for identifying these other questions that provide answers.
The basic point is that instance methods on structures are not thread-safe but static methods are.
See these questions:
These are utility methods that don't need to belong to these classes. This reinforces the Single Responsibility Principle
(edit) I was confusing with Java
(About static members):
Static class members can be used to separate data and behavior that is independent of any object identity: the data and functions do not change regardless of what happens to the object. Static classes can be used when there is no data or behavior in the class that depends on object identity.
The thread-safe point of view is also a good reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With