Scala Maps remind me of JavaScript Objects - Earvin Kayonga’s Tech Blog

Earvin Kayonga Rwogera EarvinKayonga, a Software Engineering Student

Simple Blog

Scala Maps remind me of JavaScript Objects

November 3, 2016    Scala Map JavaScript ES6

"use strict";

/ Dictionnary / const french = { la: 'the', chien: "dog", le: "the", caravane: "caravan", aboie: "barks", sur: "on" };

// the sentence to translate const phrase = "Le chien aboie sur la caravane";

let translation = phrase.toLowerCase() .split(" ") .map(word => french[${word}]) .join(" ");

console.log(translation); // print 'the dog barks on the caravan'

object Main {
  def main(args: Array[String]): Unit = {
    val french = Map[String, String] (
      "le" → "the",
      "chien" → "dog",
      "le" → "the",
      "caravane" → "caravan",
      "aboie" → "barks",
      "sur" → "on"
    )

val phrase = "Le chien aboie sur la caravane";
val translation = phrase.toLowerCase()
                        .split(" ")
                        .map(_ ⇒ french(_))
                        .mkString(" ")

println(translation)

} }


By Earvin Kayonga
follow us in feedly