Trying to understand the Iavra Localization Core.

Hi people!

I'm trying to improve my javascript skills xD
I also read a lot from the internet and ebooks. But I learn better while I'm doing it.

So, I made an add on for a plugin made by @Iavra, this one, that adds a scene for select languages.
But I think my add on is not well coded, although it's working, because I not properly understand the main plugin of Iavra.

Sayed that, I am rewriting his plugin in a way that I can understand and read it better(I also have merged Iavra Localization Core with Iavra localization menu in just one plugin), just for me to learn. Became a hobby xD

So I have difficult for rewriting the plugin parameters accordingly to the new parameters of RM MV 1.5.0+
Because it has a lot of this expression like Regex, Split, map and reduce.
I read on the internet about them, but I'm having difficulties to understand the part of the code that he shows up.
So, if anyone has the patience to show me the way... I will be GLAD!

Here's my code. Any tips that could improve my skills, I will be glad to hear!
regex means regular expression.
it's the generic term for a string, based on the contents of said string.
for example: "string" (the word, string) can be read as "letter, letter, letter, letter,...", or, "letters, starting with S, ending with G, lower case"
there's also search codes for beginning of line, ending of line, single number, groups of numbers, specific characters, etc.
regex are used when you want to look for a certain code word or parameter that obeys a certain rule, but you don't know what that word it's going to be, like, "all command words must be capitalized and end with a period.", so that's what you look for: "\[A-Z]+\.", "any capital letter from the set A to Z, as lengthy as found, and, one period."
if the code word must start with a specific string, you can add that into the whole search string: "^'code'\w+\.$", "code" as the beginning part, followed by whatever characters, ending with a period, right before end of string"
numbers, or passwords: "\d{5,8}", "numbers, at least 5 long, at most 8 long."

"split" is a string command, and is used to split the string it's called with, according to a given parameter.
the syntax is "string.split('separator'[, limit])", meaning, you call the split command after a string object, you specify which character or sub string will be used to cut the string, and how many results will be returned.
the bracketed part is optional, meaning, if you do provide it, you have to provide it after the separator, separating both parameters with a comma.
for example, if you want to split "this string of text will be split" at each space, you call string.split(' '), and it'll return every word as it's own string, in an array: ['this', 'string', 'of', 'text', 'will', 'be', 'split'].
same procedure, with a limit: "this string of text will be split".split(' ', 2) => ['this', 'string']
same thing, with specific retrieval: "this string of text will be split".split(' ', 4)[0] => ['this']
"this string of text will be split".split(' ', 4)[0] -----> ['this', 'string', 'of', 'text'][0] -----> ['this']
since ['this', 'string', 'of', 'text'] is an array, [0] returns the first item of that array, which is 'this'.

"map" is an iterator function that brings the results of executing a function to the contents of one array, into another.
Array.map(function(param){ code })
[1,2,3,4,5].map( function(num) { return num * 2 } ) ==> [1*2, 2*2, 3*2, 4*2, 5*2] ==> [2,4,6,8,10]
"take array Array, call each item 'num', take 'num', return 'num' times 2"
it's the shorthand version of using a loop to call the same function:
Code:
array = [1,2,3,4,5]
array2 = []
for (x = 0, x < array.length, x++):
  result = array[x] * 2
  array2.push(result)
end

"reduce" is similar, but it returns one single value, by passing the result of the operation to the next loop:
Array.reduce(function(param){ code })
[1,2,3,4,5].reduce(function(accumulator, value){ return accumulator + value} ) => 15
at the first pass, "accumulator" is set to 0, and "value" is set to the first item of the array => 0 + 1 = 1
at the second pass, "accumulator is set to the previous result, 1, and "value" takes the value of the second item of the array => 1 + 2 = 3
third pass, 3 + 3 = 6, etc
similar to this block:
Code:
array = [1,2,3,4,5]
accumulator = 0
for (x = 0, x < array.length, x++):
 value = array[x]
 result = accumulator + value
 accumulator = result
end
print accumulator
@gstv87 Thanks for this great explanation!!
With it, I already got to solve the plugin parameters! It's not everything but it's a way for me to go!
I will come back here to say if I make it perfect or not!
Thanks!

[EDIT]Thanks! I got it!
I have made my changes and understand the code!
😀👍

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-understand-the-iavra-localization-core.111261/