From 42dbe7222c802ef062440c0bfb7f76faed1735f6 Mon Sep 17 00:00:00 2001 From: Charles Van den Bergh Date: Tue, 18 Feb 2020 11:53:17 +0100 Subject: [PATCH 1/2] first draft --- starter-code/jasmine/jasmine-2.8.0/jasmine-html.js | 2 +- starter-code/src/functions-and-arrays.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/starter-code/jasmine/jasmine-2.8.0/jasmine-html.js b/starter-code/jasmine/jasmine-2.8.0/jasmine-html.js index 9b32bf2c1..4bc918828 100644 --- a/starter-code/jasmine/jasmine-2.8.0/jasmine-html.js +++ b/starter-code/jasmine/jasmine-2.8.0/jasmine-html.js @@ -7,7 +7,7 @@ a copy of this software and associated documentation files (the without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to -the following conditions: +the following conditions:B The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index 720d3dcf5..d7d6114b0 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -1,4 +1,9 @@ // Iteration #1: Find the maximum +function maxOfTwoNUmbers(num1,num2) { + if (num1>num2) { + return num1; + } +} // Iteration #2: Find longest word const words = ['mystery', 'brother', 'aviator', 'crocodile', 'pearl', 'orchard', 'crackpot']; From affa9e96705ad372321522814546005b72c913d3 Mon Sep 17 00:00:00 2001 From: Charles Van den Bergh Date: Tue, 18 Feb 2020 22:35:03 +0100 Subject: [PATCH 2/2] done --- starter-code/SpecRunner.html | 2 +- starter-code/src/functions-and-arrays.js | 158 ++++++++++++++++++++++- 2 files changed, 158 insertions(+), 2 deletions(-) diff --git a/starter-code/SpecRunner.html b/starter-code/SpecRunner.html index 73c156ffd..2c030633b 100644 --- a/starter-code/SpecRunner.html +++ b/starter-code/SpecRunner.html @@ -14,7 +14,7 @@ - + diff --git a/starter-code/src/functions-and-arrays.js b/starter-code/src/functions-and-arrays.js index d7d6114b0..27ca30dc6 100644 --- a/starter-code/src/functions-and-arrays.js +++ b/starter-code/src/functions-and-arrays.js @@ -1,25 +1,122 @@ // Iteration #1: Find the maximum -function maxOfTwoNUmbers(num1,num2) { +function maxOfTwoNumbers(num1,num2) { if (num1>num2) { return num1; + } else if (num1=0; i--) { + if (arr[i].length >= longestWord.length) { + longestWord = arr[i]; + } + } + return longestWord; + } + // Iteration #3: Calculate the sum const numbers = [6, 12, 1, 18, 13, 16, 2, 1, 8, 10]; +function sumNumbers(arr) { + var sum = 0; + for (var i=0; i< arr.length; i++) { + sum += arr[i]; + } +return sum; +} + +// Iteration #3: BONUS + + mixedArr = [6, 12, 'miami', 1, true, 'barca', '200', 'lisboa', 8, 10]; + +function sum (arr) { + var sum = 0; + for (var i=0; i< arr.length; i++) { + if (typeof arr[i] === "string") { + sum += arr[i].length; + } else if (typeof arr[i] === "number"){ + sum += arr[i]; + } else if (typeof arr[i] === "boolean") { + if (true) { + sum += 333 + } else if (false) { + sum += 0 + } + } else { + throw "Error"; + } +} +return sum; +} + + // Iteration #4: Calculate the average // Level 1: Array of numbers const numbersAvg = [2, 6, 9, 10, 7, 4, 1, 9]; +function averageNumbers(arr) { + if (arr.length == 0) { + return null; + } + return sumNumbers(arr) / arr.length; +} + + // Level 2: Array of strings const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace']; +function averageWordLength(arr) { +var sumOfLetters = 0; +if (arr.length == 0) { + return null; +} +for (var i=0; i