Posts

Showing posts from May, 2023

Coding challenge #1

Image
  const data1 = [ 17 , 21 , 23 ]; const data2 = [ 12 , 5 , - 5 , 0 , 4 ]; // function declaration function printForecast ( arr ) { let str = "" ; for ( let i = 0 ; i < arr .length; i ++ ) { str += ` ${ arr [i] } ÂșC in ${ i + 1 } days ... ` ; } console. log ( "..." + str); } printForecast (data1); printForecast (data2);

Problem 1 and 2

Image
  1)  // Remember, we're gonna use strict mode in all scripts now! "use strict" ; /////////////////////////////////////// // Using Google, StackOverflow and MDN // PROBLEM 1: // We work for a company building a smart home thermometer. Our most recent task is this: "Given an array of temperatures of one day, calculate the temperature amplitude. Keep in mind that sometimes there might be a sensor error." const temperatures = [ 3 , - 2 , - 6 , - 1 , "error" , 9 , 13 , 17 , 15 , 14 , 9 , 5 ]; // 1) Understanding the problem // - What is temp amplitude? Answer: difference between highest and lowest temp // - How to compute max and min temperatures? // - What's a sensor error? And what do do? // 2) Breaking up into sub-problems // - How to ignore errors? // - Find max value in temp array // - Find min value in temp array // - Subtract min from max (amplitude) and return it // function Expression const calcTempAmplitude = function ( temps ) { let ...