EcmaScript6

I started with this code which motivated me to explore ES6 further.

        let m = new Map();

        m.set("x",3);
        m.set("y",5);

        for (let [k, value] of m.entries()) {
            m.set(k, (m.get(k) * 2))
        }

        for (let value of m.entries()){
            console.log('Value [' + value + ']');

        }

Earlier I had cooed with pleasure when I coded this.

Now I want to push my luck. So I managed to wangle this code in bits and pieces from some EcmaScript6 aficianodos 🙂

I find it hard to admit that this code is not easy even for someone who claims to have rich experience with Java and software !! Bugs in this code are a different matter altogether.

Moreover since the sorted order changes somehow the result is different than the result of the Java code but I don’t have the motivation to fix this. This is actually an investigation of EcmaScript6 after all.

        var map = new Map;
        Array.from("mainn")
            .map(c => c.toLowerCase())
            .forEach(c => map.set(c, (map.get(c) | 0) + 1));

        let a = [...map.entries()];

        var x = 26;
        a.sort(([k1, v1], [k2, v2]) => v1 < v2).forEach(([k, v]) =>
                                                        {
                                                            console.log( 'k [' + k + '] v [' + v * x--+ ']');
                                                        });
LOG: 'Value [m,1]'
LOG: 'Value [a,1]'
LOG: 'Value [i,1]'
LOG: 'Value [n,2]'

LOG: 'k [n] v [52]'
LOG: 'k [m] v [25]'
LOG: 'k [a] v [24]'
LOG: 'k [i] v [23]'

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: