Sunday, June 12, 2016

Array Class - C#, C++, JavaScript, Java

June 12, 2016

Memorize all API of array definitely will help performance, help to communicate and fast coding. Just invest time to read, memorize, and practice. More reading leads great coding experience.

Ask questions about design, why they share the same, what is difference. So, like bible verse, you will come out the API just in second when you have a problem to solve.

A small research about good programmer vs good googler:
http://juliachencoding.blogspot.ca/2016/06/good-programmer-or-just-good-googler.html

So, Julia starts to go over all API of Array class first:

in C#: (once a week, spend 30 minutes to go over all examples, memorize them all!)

https://msdn.microsoft.com/en-us/library/system.array(v=vs.110).aspx

It is an abstract class Array, implementing 6 interfaces:
   IConeable,
   IList,
   ICollection,
   IEnumerable,
   IStructuralComparable,
   IStructuralEquatable

Property:
IsFixedSize
IsReadOnly
IsSynchronize
Length
LongLength
Rank
SyncRoot

C# array method:
https://msdn.microsoft.com/en-us/library/system.array_methods(v=vs.110).aspx

40 methods:  (June 16, 2016, Go over them one by one, mark favorite ones)

AsReadOnly(T) (20 minutes June 19, 2016)
BinarySearch
Clear
Clone
ConstrainedCopy
ConvertAll
Copy
CopyTo
CreateInstance
Empty(T)


Exists(T)
Find(T)
FindAll(T)
FindIndex
FindLast(T)
FindLastIndex
ForEach(T)
GetEnumerator
GetLength
GetLongLength

GetLowerBound
GetUpperBound
GetValue
IndexOf
Initialize
LastIndexOf
Resize(T)
Reverse
SetValue
IList.Add

IList.Clear
IList.Contains
IList.IndexOf
IList.Insert
IList.Remove
IList.RemoveAt
IStructuralComparable.CompareTo
IStructuralEquatable.Equals
IStructuralEquatable.GetHashCode
TrueForAll(T)

Have to work on Enumerable 50 methods first:

System.Linq > Enumerable Class > Enumerable 50 Methods:

https://msdn.microsoft.com/en-us/library/bb342261(v=vs.100).aspx

Aggregate
All(TSource)
Any
AsEnumerable(TSource)
Average
Cast(TResult)
Concat(TSource)
Contains
Count
DefaultIfEmpty

Distinct
ElementAt(TSource)
ElementAtOrDefault(TSource)
Empty(TResult)
Except
First
FirstOrDefault
GroupBy
GroupJoin
Intersect

Join
Last
LastOrDefault
LongCount
Max
Min
OfType(TResult)
OrderBy
OrderByDescending
Range

Repeat(TResult)
Reverse(TSource)
Select
SelectMany
SequenceEqual
Single
SingleOrDefault
Skip(TSource)
SkpWhile
Sum

Take(TSource)
TakeWhile
ThenBy
ThenByDescending
ToArray(TSource)
ToDictionary
ToList(TSource)
ToLookup
Union
Where

JavaScript 
http://www.w3schools.com/jsref/jsref_obj_array.asp
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype (June 14, 2016 - go over 2 hours)
Array Methods - 25 methods

concat
copyWithin
every
fill
filter
findIndex
forEach
indexOf
isArray
join


lastIndexOf
map
pop
push
reduce
reduceRight
reverse
shift
slice
some


sort
splice
toString
unshift
valueOf


Study on June 13, 2016:
copyWithin - 3 arguments, target, start (required), end(required) (optional)

You should not use an array as associative arrays

http://andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from

Study:
compare to JavaScript Set object
Set

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set

Map

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map


JavaScript reference:

https://msdn.microsoft.com/en-us/library/yek4tbz0(v=vs.94).aspx

Array object:
https://msdn.microsoft.com/en-us/library/k4h76zbx(v=vs.94).aspx

JavaScript array study:  June 30, 2016

PROPERTY:
3 properties:

constructor,
length
prototype




constructor property:
https://msdn.microsoft.com/en-us/library/jj155291(v=vs.94).aspx


length:

array is sparse, so the array is not contiguous. The length is not necessarily the number of elements in the array.
https://msdn.microsoft.com/en-us/library/d8ez24f2(v=vs.94).aspx


Prototype:

https://msdn.microsoft.com/en-us/library/jj155285(v=vs.94).aspx


JavaScript array 29 methods:

Spend 10 minutes a time to memorize all the function names, and then, try to guess each api's task, what are the arguments, how it is designed.

write down:
Array.from   - copy array from, input argument is array.
isArray      - Array.isArray(arr)  input argument arr is array
of           - ? wild guess -
concat       - arr1.concat(arr2), concatenate the string
entries      - entries  - arguments: startIndex, endIndex, return subarray?

every        - iterator - go through each node in the array to check some logic?
fill         - fill - arr.fill(1), all the elements in the array are assigned to the same value
filter  
findIndex
foreach

indexof
join
keys
lastIndexOf
map

pop
push
reduce
reduceRight
reverse

shift
slice
some
sort
splice

toString
unshift
valueOf
values

challenges:
  Arguments:
  callback funciton -

  callback function syntax

  3 things Julia likes the JavaScript Array.fill function design:
   - start, end arguments are options
   - negative start, end arguments handling
   -
 
-- end of June 30, 2016 study --
-- End of JavaScript --

-----     Java ---
Java Array reference:
https://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Array.html

Java Array

Method inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait

Method detail:
Array.newInstance

getLength
get  - Array.get(array, index)

getBoolean - Array.getBoolean(array, index)

getByte - Array.getByte(array, index)

getChar - Array.getChar(array, index)


getShort - Array.getShort(arrray, index)

getInt
getLong
getFloat
getDouble

set - Array.set(array, index, Object value)

setBoolean
setByte
setChar   - Array (Object array, int index, char c)
setShort
setInt
setLong
setFloat
setDouble

Java 
Arrays

https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html

asList
binarySearch

copyOf
copyOfRange
deepEquals
deepHashCode
deepToString
equals
fill
hashCode
sort
toString

Methods inherited from class java.lang.Object

clone, equals, finalize, hashCode, notify, notifyAll, toString, wait.

blogs to read:
asList
http://stackoverflow.com/questions/20538869/what-is-the-best-way-of-using-arrays-aslist-to-initialize-a-list


copyOfRange:
http://www.tutorialspoint.com/java/util/arrays_copyofrange_short.htm

http://stackoverflow.com/questions/11001720/get-only-part-of-an-array-in-java

more than 2 ways:
   1. copyOfRange
   2. Arrays.asList(array).subList(index, array.Length)

 
http://stackoverflow.com/questions/19389609/array-vs-arraylist-in-performance

http://stackoverflow.com/questions/716597/array-or-list-in-java-which-is-faster

  notes: List   vs ArrayList   List is interface, whereas ArrayList is a concrete class to create object.

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

No comments:

Post a Comment