Grammalecte  Check-in [33dbc61ec2]

Overview
Comment:[fr][js] conj generator: Array.from() is much more readable than .slice(0) to clone an Array
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fr | multid
Files: files | file ages | folders
SHA3-256: 33dbc61ec2e8400e383edf12c66afe2dd5e95f9dace16a06ab20beb233e3aee1
User & Date: olr on 2018-03-11 23:39:11
Other Links: branch diff | manifest | tags
Context
2018-03-12
12:12
[tb] lexicon editor: ui update check-in: 600f33b256 user: olr tags: tb, multid
2018-03-11
23:39
[fr][js] conj generator: Array.from() is much more readable than .slice(0) to clone an Array check-in: 33dbc61ec2 user: olr tags: fr, multid
23:28
[fr][bug] conj generator: clone array/list before adding elements check-in: 2ce9bd0c2a user: olr tags: fr, multid
Changes

Modified gc_lang/fr/modules-js/conj_generator.js from [d5f86107a9] to [354852a8f0].

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
53
54

55
56

57
58
59
60
61

62
63
64
65

66
67
68
69
70
71

72
73
74
75
76
77
78
35
36
37
38
39
40
41

42
43
44
45
46
47

48
49
50
51
52

53
54

55
56
57
58
59

60
61
62
63

64
65
66
67
68
69

70
71
72
73
74
75
76
77







-






-
+




-
+

-
+




-
+



-
+





-
+







        if (sVerb.endsWith("re")) {
            return "3";
        }
        return "4";
    },

    getConjRules: function (sVerb, bVarPpas=true, nGroup=2) {
        // .slice(0): clone an Array
        let lConj = null;
        let sVarPpas = (bVarPpas) ? "true" : "false";
        if (sVerb.endsWith("er")) {
            // premier groupe, conjugaison en fonction de la terminaison du lemme
            // 5 lettres
            if (sVerb.slice(-5) in this.oConj["V1"]) {
                lConj = this.oConj["V1"][sVerb.slice(-5)].slice(0);
                lConj = Array.from(this.oConj["V1"][sVerb.slice(-5)]);
            }
            // 4 lettres
            else if (sVerb.slice(-4) in this.oConj["V1"]) {
                if (sVerb.endsWith("eler") || sVerb.endsWith("eter")) {
                    lConj = this.oConj["V1"][sVerb.slice(-4)]["1"].slice(0);
                    lConj = Array.from(this.oConj["V1"][sVerb.slice(-4)]["1"]);
                } else {
                    lConj = this.oConj["V1"][sVerb.slice(-4)].slice(0);
                    lConj = Array.from(this.oConj["V1"][sVerb.slice(-4)]);
                }
            }
            // 3 lettres
            else if (sVerb.slice(-3) in this.oConj["V1"]) {
                lConj = this.oConj["V1"][sVerb.slice(-3)].slice(0);
                lConj = Array.from(this.oConj["V1"][sVerb.slice(-3)]);
            }
            // 2 lettres
            else {
                lConj = this.oConj["V1"]["er"].slice(0);
                lConj = Array.from(this.oConj["V1"]["er"]);
            }
            lConj.push(...this.oConj["V1_ppas"][sVarPpas]);
        }
        else if (sVerb.endsWith("ir") && nGroup <= 2) {
            // deuxième groupe
            lConj = this.oConj["V2"].slice(0);
            lConj = Array.from(this.oConj["V2"]);
            lConj.push(...this.oConj["V2_ppas"][sVarPpas]);
        }
        else {
            // TODO: troisième groupe
            lConj = [ [0, "", ":Y/*", false] ];
        }
        return lConj;