Code Monkey home page Code Monkey logo

maps_and_sets-es2015's Introduction

Maps and Sets Exercise

Quick Question #1

What does the following code return?

new Set([1,1,2,2,3,4])
  • new Set([1,1,2,2,3,4])
    • returns Set(4) { 1, 2, 3, 4 }

Quick Question #2

What does the following code return?

[...new Set("referee")].join("")
  • [...new Set("referee")].join("")
    • returns "ref"

Quick Questions #3

What does the Map m look like after running the following code?

let m = new Map();
m.set([1,2,3], true);
m.set([1,2,3], false);
  • m
    • returns Map(2)ย {Array(3) => true, Array(3) => false}

hasDuplicate

Write a function called hasDuplicate which accepts an array and returns true or false if that array contains a duplicate

hasDuplicate([1,3,2,1]) // true
hasDuplicate([1,5,-1,4]) // false
const hasDuplicate = a => new Set(a).size !== a.length;

vowelCount

Write a function called vowelCount which accepts a string and returns a map where the keys are numbers and the values are the count of the vowels in the string.

vowelCount('awesome') // Map { 'a' => 1, 'e' => 2, 'o' => 1 }
vowelCount('Colt') // Map { 'o' => 1 }
const vowelCount = str => str.toLowerCase().split("").reduce((a, v) => {
    if ("aeiou".includes(v))
        a.has(v) ? a.set(v, a.get(v) + 1) : a.set(v, 1);
    return a;
}, new Map());

maps_and_sets-es2015's People

Contributors

blinter avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.