From af102d67147ba0f12776f63a9bf0400a090ad42f Mon Sep 17 00:00:00 2001 From: Frank Oosterhuis Date: Mon, 19 Oct 2020 13:01:24 +0200 Subject: Challenge083 - Task #1 --- challenge-083/frankivo/WordsLength.scala | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 challenge-083/frankivo/WordsLength.scala diff --git a/challenge-083/frankivo/WordsLength.scala b/challenge-083/frankivo/WordsLength.scala new file mode 100644 index 0000000000..eec2dee30c --- /dev/null +++ b/challenge-083/frankivo/WordsLength.scala @@ -0,0 +1,22 @@ +object WordsLength { + val examples: Seq[String] = Seq( + "The Weekly Challenge", + "The purpose of our lives is to be happy" + ) + + def main(args: Array[String]): Unit = { + examples + .map(e => (e, count(e))) + .foreach(println) + } + + def count(line: String) : Int = { + val words = line.split(" ") + + words + .drop(1) + .take(words.length - 2) + .mkString + .length + } +} \ No newline at end of file -- cgit