From ce4854339986413e849f5dbd4393db0ec636c4f7 Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Fri, 13 Mar 2020 10:06:33 +0100 Subject: [PATCH 01/41] questions solved --- warmUp1.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/warmUp1.js b/warmUp1.js index 359b609..d73f4ac 100644 --- a/warmUp1.js +++ b/warmUp1.js @@ -1,6 +1,25 @@ // 1-using + operator combine your partner first and last name . +var firstName = "Mohamed Amine" ; +var lastName = "Oueslati" ; +var fullName = firstName + " " + lastName ; + console.log (fullName) ; + // 2-find if the number 13 is a multiple of 3 or not. +var x = 13 ; +if ( x % 3 === 0 ) { + console.log ("13 is a multiple of 3") ; +} + console.log ("13 is not a multiple of 3") ; + // 3-calculate the average age of the follwing ages [13,14,13,15,16,17,19,13,16,15] -// 4-calculate your age in seconds. +var array = [13,14,13,15,16,17,19,13,16,15] ; +var sum = 0 ; + for (var i=0 ; i < array.length ; i++) { + sum += array[i] ; + } + console.log(sum/array.length) ; -// your code is here +// 4-calculate your age in seconds. +var age = 28 ; +var ageInSeconds = age * 365 * 24 * 60 * 60 ; + console.log (ageInSeconds) ; From 9a3bc1afb5244db347b198a56c1d59d328227178 Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Sat, 14 Mar 2020 09:01:25 +0100 Subject: [PATCH 02/41] warmUp2 --- warmUp2.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 warmUp2.js diff --git a/warmUp2.js b/warmUp2.js new file mode 100644 index 0000000..a6d6932 --- /dev/null +++ b/warmUp2.js @@ -0,0 +1,26 @@ +// 1 - Complete the function cube that returns the cube of x: + +function cube(x) { + // your code here +} + +// 2 - Write a function sameLength that accepts two strings as arguments, and returns true if those strings have the same length, and false otherwise. + +function sameLength(string1, string2) { + // your code here +} + +// 3 - Write a function called scoreToGrade that accepts a number as a parameter and returns a string representing a letter grade corresponding to that score. + +function scoreToGrade(number) { + // your code here +} +// Repeating a String n Times: Let's write a function called repeatString that takes two parameters: a string str, which is the string to be repeated, and count -- a number representing how many times the string str should be repeated +// repeatString('dog', 0); // => '' +// repeatString('dog', 1); // => 'dog' +// repeatString('dog', 2); // => 'dog' + 'dog' => 'dogdog' +// repeatString('dog', 3); // => 'dog' + 'dog' + 'dog' => 'dogdogdog' + +function repeatString(str, count) { + // TODO: your code here +} From b6d9181a5da11874e4d98f4d0f2d685b4e6a64f9 Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Sat, 14 Mar 2020 09:06:23 +0100 Subject: [PATCH 03/41] updated --- warmUp2.js | 1 + 1 file changed, 1 insertion(+) diff --git a/warmUp2.js b/warmUp2.js index a6d6932..42f5983 100644 --- a/warmUp2.js +++ b/warmUp2.js @@ -15,6 +15,7 @@ function sameLength(string1, string2) { function scoreToGrade(number) { // your code here } +// USE RECURSION // Repeating a String n Times: Let's write a function called repeatString that takes two parameters: a string str, which is the string to be repeated, and count -- a number representing how many times the string str should be repeated // repeatString('dog', 0); // => '' // repeatString('dog', 1); // => 'dog' From 5cd35320fb68030b63e3ae036d4334b2fcdd2d9f Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Sat, 14 Mar 2020 10:27:51 +0100 Subject: [PATCH 04/41] questions solved --- warmUp2.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/warmUp2.js b/warmUp2.js index 42f5983..e90b78e 100644 --- a/warmUp2.js +++ b/warmUp2.js @@ -1,19 +1,33 @@ // 1 - Complete the function cube that returns the cube of x: function cube(x) { - // your code here + return (x * x * x) ; } // 2 - Write a function sameLength that accepts two strings as arguments, and returns true if those strings have the same length, and false otherwise. function sameLength(string1, string2) { - // your code here + if (string1.length === string2.length) { + return true ; + } + return false ; } // 3 - Write a function called scoreToGrade that accepts a number as a parameter and returns a string representing a letter grade corresponding to that score. function scoreToGrade(number) { - // your code here + if (number > 90 && number <= 100) { + return "A" ; + } + else if (number > 80 && number <= 90) { + return "B" ; + } + else if (number > 70 && number <= 80) { + return "C" ; + } + else if (number > 60 && number <= 70) { + return "D" ; + } } // USE RECURSION // Repeating a String n Times: Let's write a function called repeatString that takes two parameters: a string str, which is the string to be repeated, and count -- a number representing how many times the string str should be repeated @@ -23,5 +37,9 @@ function scoreToGrade(number) { // repeatString('dog', 3); // => 'dog' + 'dog' + 'dog' => 'dogdogdog' function repeatString(str, count) { - // TODO: your code here -} + if (count === 0) { + return '' ; + } + count-- ; + return str += repeatString(str, count) +} \ No newline at end of file From 87d1ed2d16e10c1a29cf07bf66d1b516783bcf2c Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Mon, 16 Mar 2020 09:11:19 +0100 Subject: [PATCH 05/41] warmUp3 is pushed --- warmUp3.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 warmUp3.js diff --git a/warmUp3.js b/warmUp3.js new file mode 100644 index 0000000..ae817da --- /dev/null +++ b/warmUp3.js @@ -0,0 +1,21 @@ +// 1 - Write functions larger and smaller that each accept two strings as arguments, and return the larger and smaller strings, respectively + +// 2 - Write a function called counter that, when invoked, always returns a number that is one more than the previous invocation. For instance: +// function counting(n) { + TODO: your code here +// } +// counting(5); // => '1, 2, 3, 4, 5' +// counting(1); // => '1' +// counting(3); // => '1, 2, 3' + + +// 3 - Meet & Greet: n numbers are coming to a party for numbers. Introduce them each to all the guests as they arrive. You should end up with output looking something like this one for n = 5 +// welcome 1 +// welcome 2, meet 1 +// welcome 3, meet 1 and 2 +// welcome 4, meet 1, 2 and 3 +// welcome 5, meet 1, 2, 3 and 4 +// + +// 4- Write a function shortestWord that works like longestWord, but returns the shortest word instead. + From 68e0a89824f27f30e294dc48d310ddda32afa6a7 Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Mon, 16 Mar 2020 09:59:19 +0100 Subject: [PATCH 06/41] questions solved --- warmUp3.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 warmUp3.js diff --git a/warmUp3.js b/warmUp3.js new file mode 100644 index 0000000..8c516ad --- /dev/null +++ b/warmUp3.js @@ -0,0 +1,72 @@ +// 1 - Write functions larger and smaller that each accept two strings as arguments, and return the larger and smaller strings, respectively + +function larger (str1,str2) { + if (str1.length > str2.length) { + return str1 + } + return str2 +} + +function smaller (str1,str2) { + if (str1.length > str2.length) { + return str2 + } + return str1 +} + +// 2 - Write a function called counter that, when invoked, always returns a number that is one more than the previous invocation. For instance: +var newNumber; + +function counter(n){ + return newNumber = (n + 1); +} + + +// 3 - Meet & Greet: n numbers are coming to a party for numbers. Introduce them each to all the guests as they arrive. You should end up with output looking something like this one for n = 5 +// welcome 1 +// welcome 2, meet 1 +// welcome 3, meet 1 and 2 +// welcome 4, meet 1, 2 and 3 +// welcome 5, meet 1, 2, 3 and 4 +// + +function meetAndGreet(n) { + var counter = 1; + var x; + var total = ''; + while (counter <= n) { + if (n === 1) { + total = 'welcome ' + counter + } else if (counter === 1) { + total = 'welcome ' + counter + ' '; + } else { + total = total + 'welcome ' + counter + ', ' + 'meet '; + x = 1; + while (x < counter) { + if (x === counter - 2) { + total = total + x + ' and '; + } else if (x === counter - 1) { + total = total + x; + } else { + total = total + x + ', '; + } + x += 1; + } + total = total + ' ' ; + } + counter += 1; + } + return total; + } +// 4- Write a function shortestWord that works like longestWord, but returns the shortest word instead. + +function shortestWord (str) { + var array = str.split(' ') ; + var string = array[0] + for ( var i = 0 ; i < array.length ; i++) { + if (array[i].length < string.length ) { + string = array[i] ; + } + } + return string ; +} From 4ab3967cd0764bea1a7614a1d87ac2da4d6ea391 Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Mon, 16 Mar 2020 21:19:14 +0100 Subject: [PATCH 07/41] warmUp 4 --- warmUp3.js | 12 +++++------- warmUp4.js | 8 ++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 warmUp4.js diff --git a/warmUp3.js b/warmUp3.js index ae817da..9e5778b 100644 --- a/warmUp3.js +++ b/warmUp3.js @@ -1,14 +1,13 @@ // 1 - Write functions larger and smaller that each accept two strings as arguments, and return the larger and smaller strings, respectively // 2 - Write a function called counter that, when invoked, always returns a number that is one more than the previous invocation. For instance: -// function counting(n) { - TODO: your code here -// } -// counting(5); // => '1, 2, 3, 4, 5' -// counting(1); // => '1' +// function counting(n) { +// TODO: your code here +// } +// counting(5); // => '1, 2, 3, 4, 5' +// counting(1); // => '1' // counting(3); // => '1, 2, 3' - // 3 - Meet & Greet: n numbers are coming to a party for numbers. Introduce them each to all the guests as they arrive. You should end up with output looking something like this one for n = 5 // welcome 1 // welcome 2, meet 1 @@ -18,4 +17,3 @@ // // 4- Write a function shortestWord that works like longestWord, but returns the shortest word instead. - diff --git a/warmUp4.js b/warmUp4.js new file mode 100644 index 0000000..6db784a --- /dev/null +++ b/warmUp4.js @@ -0,0 +1,8 @@ +// 1-write a function that returns the product of any number by 3. + +// 2-complete the following function multiply to return the result of multiplying of x and y + +// 3-complete the following function that Convert Fahrenheit to Celsius if the module for converting is +// (5/9) * (fahrenheit-32); + +// 4-Define a function named "sqArea", and make it display square area if you knew the length of its side. From 6e144bf43307a076854a37dd71b17f4dc1cd63ae Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Tue, 17 Mar 2020 09:34:10 +0100 Subject: [PATCH 08/41] questions solved --- warmUp4.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 warmUp4.js diff --git a/warmUp4.js b/warmUp4.js new file mode 100644 index 0000000..dc06705 --- /dev/null +++ b/warmUp4.js @@ -0,0 +1,19 @@ +// 1-write a function that returns the product of any number by 3. + +function product3 (number) { + return number * 3 ; +} +// 2-complete the following function multiply to return the result of multiplying of x and y +function multiply (x,y) { + return x * y ; +} +// 3-complete the following function that Convert Fahrenheit to Celsius if the module for converting is +// (5/9) * (fahrenheit-32); +function Convert (fahrenheit) { + return (5/9) * (fahrenheit-32) ; +} + +// 4-Define a function named "sqArea", and make it display square area if you knew the length of its side. +function sqArea (a) { + return a * a ; +} \ No newline at end of file From b0ec828ea6e15714eee5fd8dde21f06ed724a9b3 Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Wed, 18 Mar 2020 09:01:34 +0100 Subject: [PATCH 09/41] warmUp5 --- warmUp5.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 warmUp5.js diff --git a/warmUp5.js b/warmUp5.js new file mode 100644 index 0000000..1313865 --- /dev/null +++ b/warmUp5.js @@ -0,0 +1,43 @@ +// 1) Write a function named greaterNum that: +// - takes 2 arguments, both numbers. +// - returns whichever number is the greater (higher) number. +// ex greaterNum(5, 10) => "The greater number of 5 and 10 is 10." + +// 2) Write a function named isEven using for loop that +// - iterate from x to y. +// - return array contain the even values, +// ex: isEven(1,10) => [2,4,6,8,10] + +// function isEven(x, y) { +// var arr = []; +// for (var i = 0; i < arr.length; i++) { +// while (x <= y) { +// if (x % 2 === 0) { +// arr[i] = arr.push(x) +// } +// x++ +// } +// } +// return arr; +// } +//3) write a function named sum that +// - Use a while loop to add up the numbers from x to y. +// ex sum(1,5) => 15 + +//4) Write a function named factorial that +// - Use Recursion to calculate the factorial of a number +// - the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n +// - 5! = 5*4*3*2*1 = 120 +// ex : factorial(5) => 120 + +//5) write a function named decimals +//- the function will format a number up to specified decimal places +//- the function will return a string +//- if the parameters not a number return false +// ex : +// decimals(2100, 'a') ==> false +// decimals('a', 5) ==> false +// decimals(2.100212, 2) ==> '2.10' +// decimals(2.100212, 3) ==> '2.100' +// decimals(2100, 2) ==> '2100.00' +// From bb8f600beae6ba6bb118e46f212284106e2681e3 Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Wed, 18 Mar 2020 09:09:58 +0100 Subject: [PATCH 10/41] warmup5 --- warmUp5.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/warmUp5.js b/warmUp5.js index 1313865..0c715fa 100644 --- a/warmUp5.js +++ b/warmUp5.js @@ -9,16 +9,7 @@ // ex: isEven(1,10) => [2,4,6,8,10] // function isEven(x, y) { -// var arr = []; -// for (var i = 0; i < arr.length; i++) { -// while (x <= y) { -// if (x % 2 === 0) { -// arr[i] = arr.push(x) -// } -// x++ -// } -// } -// return arr; + // } //3) write a function named sum that // - Use a while loop to add up the numbers from x to y. From 1610c21b7d1ab235c7736dbe1ebee2e89d6f737e Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Wed, 18 Mar 2020 09:54:18 +0100 Subject: [PATCH 11/41] warmUp5 done --- warmUp5.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 warmUp5.js diff --git a/warmUp5.js b/warmUp5.js new file mode 100644 index 0000000..6e25639 --- /dev/null +++ b/warmUp5.js @@ -0,0 +1,66 @@ +// 1) Write a function named greaterNum that: +// - takes 2 arguments, both numbers. +// - returns whichever number is the greater (higher) number. +// ex greaterNum(5, 10) => "The greater number of 5 and 10 is 10." +function greaterNum (num1,num2) { + return (num1 > num2) ? "The greater number of "+num1+" and "+num2+" is "+num1+"." + : "The greater number of "+num1+" and "+num2+" is "+num2+"."; +} + +// 2) Write a function named isEven using for loop that +// - iterate from x to y. +// - return array contain the even values, +// ex: isEven(1,10) => [2,4,6,8,10] + +function isEven(x, y) { + var array = [] ; + for (var i = 0 ; x <= y ; x++) { + if (x % 2 === 0) { + array[i] = x ; + i++; + } + } + return array ; +} + +// } +//3) write a function named sum that +// - Use a while loop to add up the numbers from x to y. +// ex sum(1,5) => 15 + +function sum (x,y) { + var sum = 0 ; + while (x <= y ) { + sum += x ; + x++; + } + return sum ; +} + +//4) Write a function named factorial that +// - Use Recursion to calculate the factorial of a number +// - the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n +// - 5! = 5*4*3*2*1 = 120 +// ex : factorial(5) => 120 + +function factorial(n){ + return (n === 1 || n === 0) ? 1 : n*factorial(n-1) ; + }; + +//5) write a function named decimals +//- the function will format a number up to specified decimal places +//- the function will return a string +//- if the parameters not a number return false +// ex : +// decimals(2100, 'a') ==> false +// decimals('a', 5) ==> false +// decimals(2.100212, 2) ==> '2.10' +// decimals(2.100212, 3) ==> '2.100' +// decimals(2100, 2) ==> '2100.00' +// +function decimals (x,y) { + if (typeof x !== 'number' || typeof y !== 'number') { + return false ; + } + return x.toFixed(y) +} \ No newline at end of file From 7e2c0347dec1ec198db14146f80205e0c7faa398 Mon Sep 17 00:00:00 2001 From: hashem-buzer Date: Wed, 18 Mar 2020 11:18:00 +0100 Subject: [PATCH 12/41] =?UTF-8?q?warmUp=205=E2=9C=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmUp4.js | 7 ++++++- warmUp5.js | 24 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/warmUp4.js b/warmUp4.js index 6db784a..5f4dcd3 100644 --- a/warmUp4.js +++ b/warmUp4.js @@ -1,7 +1,12 @@ // 1-write a function that returns the product of any number by 3. +function product(number) { + return number * 3; +} // 2-complete the following function multiply to return the result of multiplying of x and y - +function multiply(n1, n2) { + return n1 * n2; +} // 3-complete the following function that Convert Fahrenheit to Celsius if the module for converting is // (5/9) * (fahrenheit-32); diff --git a/warmUp5.js b/warmUp5.js index 0c715fa..d14047b 100644 --- a/warmUp5.js +++ b/warmUp5.js @@ -3,17 +3,33 @@ // - returns whichever number is the greater (higher) number. // ex greaterNum(5, 10) => "The greater number of 5 and 10 is 10." +var greaterNum = (num1, num2) => { + return num1 > num2 ? num1 : num1 < num2 ? num2 : "equal"; +}; // 2) Write a function named isEven using for loop that // - iterate from x to y. // - return array contain the even values, // ex: isEven(1,10) => [2,4,6,8,10] -// function isEven(x, y) { +var isEven = (x, y) => { + var array = []; -// } + for (var i = x; i < y; i++) { + i % 2 === 0 ? array.push(i) : null; + } + return array; +}; //3) write a function named sum that // - Use a while loop to add up the numbers from x to y. // ex sum(1,5) => 15 +var sum = (x, y) => { + var result = 0; + + for (var i = x; i <= y; i++) { + result += i; + } + return result; +}; //4) Write a function named factorial that // - Use Recursion to calculate the factorial of a number @@ -21,6 +37,10 @@ // - 5! = 5*4*3*2*1 = 120 // ex : factorial(5) => 120 +var factorial = n => { + return n === 0 ? 1 : n * factorial(n - 1); +}; + //5) write a function named decimals //- the function will format a number up to specified decimal places //- the function will return a string From a293eee4d2c674c5243436c035f584a16e547e59 Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Thu, 19 Mar 2020 00:55:23 +0100 Subject: [PATCH 13/41] warmUp6 --- warmUp6.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 warmUp6.js diff --git a/warmUp6.js b/warmUp6.js new file mode 100644 index 0000000..7d74294 --- /dev/null +++ b/warmUp6.js @@ -0,0 +1,10 @@ +// Style your code and explain it step by step before jumping to code :D +// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ + +// 1-Define a function called myTrueFun that returns true whenever its called. + +// 2- Define a function called color in which returns true if type of the input is string and returns false otherwise. + +// 3-Write a JavaScript function that accepts a number as a parameter and check if the number is prime or not. + +// 4-write a function that accepts two numbers as parameters and returns true if the two parameters have the same value , false if not From 5fe6b78dc00e48b69b7a1736a71dc53c555653ec Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Thu, 19 Mar 2020 10:06:58 +0100 Subject: [PATCH 14/41] warmUp6 done --- warmUp6.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 warmUp6.js diff --git a/warmUp6.js b/warmUp6.js new file mode 100644 index 0000000..a1f1e00 --- /dev/null +++ b/warmUp6.js @@ -0,0 +1,33 @@ +// Style your code and explain it step by step before jumping to code :D +// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ + +// 1-Define a function called myTrueFun that returns true whenever its called. +// i wrote a function without parameters and i returned true +function myTrueFun () { + return true +} + +// 2- Define a function called color in which returns true if type of the input is string and returns false otherwise. +// i added a condition that check if the type of the value i entered is string or not and i returned true or false +function color (string) { + return (typeof(string) === 'string' ? true : false) +} +// 3-Write a JavaScript function that accepts a number as a parameter and check if the number is prime or not. +// i added a for loop to check if the rest of my number divided by all numbers less than it is equal to 0 or not ... if it is +// so the number is not a prime if its not so the number is a prime +function Prime (number) { + if (number === 1) { + return number + " is not Prime" + } + for (var n = number-1 ; n > 1; n--) { + if (number % n === 0) { + return number + " is not Prime" + } + } +return number + " is prime" +} +// 4-write a function that accepts two numbers as parameters and returns true if the two parameters have the same value , false if not +// i compared the two parameters if they are equal i returned true if they are not i returned false +function sameValue (a,b) { + return (a === b) ? true : false ; +} \ No newline at end of file From 49a776a2a1b330f827e34aaee70c22749e95e924 Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Thu, 19 Mar 2020 23:21:28 +0100 Subject: [PATCH 15/41] warmUp7 --- warmUp7.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 warmUp7.js diff --git a/warmUp7.js b/warmUp7.js new file mode 100644 index 0000000..bb45934 --- /dev/null +++ b/warmUp7.js @@ -0,0 +1,12 @@ +// 1-Choose the correct comparison operator to display "true", when: 5 is less than 7. +//answer : + +//2- Write a function named helloWorld that: +//takes 1 argument, a language code (e.g. "fr", "es", "en") +//returns "Hello, World" for the given language, for atleast 3 languages. It should default to returning English. +//ex: helloWorld('fr') ==> 'Bonjour tout le monde' +// helloWorld('es') ==> 'Hola, Mundo' +// helloWorld('') ==> 'Hello, World' + +//3- write a function to Reverse an array without use array.reverse() method: +// ex: reverseArray([1,2,3]) ==> [3,2,1] From 6ec52902076a70642276a502bd7944ad0a6f8634 Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Fri, 20 Mar 2020 09:31:21 +0100 Subject: [PATCH 16/41] warmUp7 done --- warmUp7.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 warmUp7.js diff --git a/warmUp7.js b/warmUp7.js new file mode 100644 index 0000000..5d6d766 --- /dev/null +++ b/warmUp7.js @@ -0,0 +1,35 @@ +// 1-Choose the correct comparison operator to display "true", when: 5 is less than 7. +//answer : + +console.log (5 < 7) ; + +//2- Write a function named helloWorld that: +//takes 1 argument, a language code (e.g. "fr", "es", "en") +//returns "Hello, World" for the given language, for atleast 3 languages. It should default to returning English. +//ex: helloWorld('fr') ==> 'Bonjour tout le monde' +// helloWorld('es') ==> 'Hola, Mundo' +// helloWorld('') ==> 'Hello, World' +function helloWorld (code) { + if (code === "fr") { + return 'Bonjour tout le monde' ; + } + else if (code === "es") { + return 'Hola, Mundo' ; + } + else if (code === "ar") { + return 'صباح الخير للجميع' ; + } + return 'Hello, World' ; +} + +//3- write a function to Reverse an array without use array.reverse() method: +// ex: reverseArray([1,2,3]) ==> [3,2,1] +function Reverse (array) { + var j = 0 ; + var arr = []; + for (var i = array.length-1 ; i >= 0 ; i--) { + arr[j] = array[i] ; + j++; + } + return arr ; +} \ No newline at end of file From 33c87b6bd9ca88f02531dee66c324e52b3e36853 Mon Sep 17 00:00:00 2001 From: hashem-buzer Date: Fri, 20 Mar 2020 10:20:39 +0100 Subject: [PATCH 17/41] solved --- warmUp6.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/warmUp6.js b/warmUp6.js index 7d74294..db0d319 100644 --- a/warmUp6.js +++ b/warmUp6.js @@ -2,9 +2,17 @@ // Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ // 1-Define a function called myTrueFun that returns true whenever its called. - +var myTrueFun = () => { + return true; +}; // 2- Define a function called color in which returns true if type of the input is string and returns false otherwise. +var color = input => { + return typeof input === "string" ? true : false; +}; // 3-Write a JavaScript function that accepts a number as a parameter and check if the number is prime or not. // 4-write a function that accepts two numbers as parameters and returns true if the two parameters have the same value , false if not +var same = (number1, number2) => { + return number1 === number2 ? true : false; +}; From e30243f40077b543ad5467d28679ebcab039f6e9 Mon Sep 17 00:00:00 2001 From: hashem-buzer Date: Fri, 20 Mar 2020 10:47:16 +0100 Subject: [PATCH 18/41] warmUp7 is solved --- warmUp7.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/warmUp7.js b/warmUp7.js index bb45934..3cf26ad 100644 --- a/warmUp7.js +++ b/warmUp7.js @@ -1,5 +1,5 @@ // 1-Choose the correct comparison operator to display "true", when: 5 is less than 7. -//answer : +//answer : 5 < 7 ? true : false; //2- Write a function named helloWorld that: //takes 1 argument, a language code (e.g. "fr", "es", "en") @@ -7,6 +7,28 @@ //ex: helloWorld('fr') ==> 'Bonjour tout le monde' // helloWorld('es') ==> 'Hola, Mundo' // helloWorld('') ==> 'Hello, World' +var helloWorld = lang => { + var lang = lang.toLowerCase(); + + return lang === "" + ? "Hello, World" + : lang === "fr" + ? "Bonjour tout le monde" + : lang === "es" + ? "Hola, Mundo" + : lang === "ar" + ? "صباح الخير" + : null; +}; //3- write a function to Reverse an array without use array.reverse() method: // ex: reverseArray([1,2,3]) ==> [3,2,1] +var reverse = arr => { + var result = []; + + for (var i = arr.length - 1; i >= 0; i--) { + result.push(arr[i]); + } + + return result; +}; From 69e466b56ec53a012dc13b819bebda0ed79bed29 Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Sat, 21 Mar 2020 01:55:56 +0100 Subject: [PATCH 19/41] warmUp 8 --- warmUp8.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 warmUp8.js diff --git a/warmUp8.js b/warmUp8.js new file mode 100644 index 0000000..11e4be0 --- /dev/null +++ b/warmUp8.js @@ -0,0 +1,8 @@ +// 1 - Write a function named objKey that take an object as a parameter and returns an array containing the keys of the object +// objKey({name:'ahmed',age:20}) ==> ['name','age'] + +// 2 - Write a function named objLength to get the length of a JavaScript object +// objLength({name:'ahmed',age:20}) ==> 2 + +// 3 - Write a function named objSort to sort an array of JavaScript objects based on the id +// objSort([{id:2,value:50},{id:0,value:70},{id:1,value:40}]) ==> [{id:0,value:70},{id:1,value:40},{id:2,value:50}] From c12c2588010cbdba1ae1487cd3d0803bf2ce8454 Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Sat, 21 Mar 2020 10:05:41 +0100 Subject: [PATCH 20/41] warmUp8 done --- warmUp8.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 warmUp8.js diff --git a/warmUp8.js b/warmUp8.js new file mode 100644 index 0000000..54335a7 --- /dev/null +++ b/warmUp8.js @@ -0,0 +1,32 @@ +// 1 - Write a function named objKey that take an object as a parameter and returns an array containing the keys of the object +// objKey({name:'ahmed',age:20}) ==> ['name','age'] + +function objKey (obj) { + return Object.keys(obj) ; +} + +// 2 - Write a function named objLength to get the length of a JavaScript object +// objLength({name:'ahmed',age:20}) ==> 2 +function objLength (obj) { + var arr = [] ; + var i = 0 ; + for (var key in obj) { + arr[i] = obj.hasOwnProperty(key) ; + i++; + } + return arr.length ; +} + +// 3 - Write a function named objSort to sort an array of JavaScript objects based on the id +// objSort([{id:2,value:50},{id:0,value:70},{id:1,value:40}]) ==> [{id:0,value:70},{id:1,value:40},{id:2,value:50}] +function objSort (array) { +var arr = [] + for (var j = 0 ; j < array.length ; j++) { + for (var i = 0 ; i < array.length ; i++) { + if ( array[i].id === j ) { + arr[j] = array[i] ; + } + } + } + return arr ; +} \ No newline at end of file From 943001a98aadac6dd9c64a55cae59f40e27fede5 Mon Sep 17 00:00:00 2001 From: hashem-buzer Date: Sat, 21 Mar 2020 11:12:11 +0100 Subject: [PATCH 21/41] =?UTF-8?q?warmUp8=20=E2=9C=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmUp8.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/warmUp8.js b/warmUp8.js index 11e4be0..62192ac 100644 --- a/warmUp8.js +++ b/warmUp8.js @@ -1,8 +1,33 @@ // 1 - Write a function named objKey that take an object as a parameter and returns an array containing the keys of the object // objKey({name:'ahmed',age:20}) ==> ['name','age'] - +var objKey = obj => { + return Object.keys(obj); +}; // 2 - Write a function named objLength to get the length of a JavaScript object // objLength({name:'ahmed',age:20}) ==> 2 +var objLength = obj => { + return Object.keys(obj).length; +}; // 3 - Write a function named objSort to sort an array of JavaScript objects based on the id // objSort([{id:2,value:50},{id:0,value:70},{id:1,value:40}]) ==> [{id:0,value:70},{id:1,value:40},{id:2,value:50}] + +var objSort = (array, track, newArr) => { + var track = track || 0; + var newArr = newArr || []; + + if (newArr.length === array.length) { + return newArr; + } + + for (var i = 0; i < array.length; i++) { + console.log(array[i].id, "the array element"); + + if (array[i].id === track) { + console.log(array[i], "the if array[i].id"); + newArr.push(array[i]); + } + } + + return objSort(array, ++track, newArr); +}; From 688273ddf9484c898f62671ccf713b776d583b29 Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Mon, 23 Mar 2020 00:01:03 +0100 Subject: [PATCH 22/41] warmUp 9 --- warmUp9.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 warmUp9.js diff --git a/warmUp9.js b/warmUp9.js new file mode 100644 index 0000000..b05ef52 --- /dev/null +++ b/warmUp9.js @@ -0,0 +1,34 @@ +// Style your code and explain it step by step before jumping to code :D +// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ + +//1. Write a JavaScript function to check whether an `input` is an array or not +// ex isArray([1,2])=>true +// isArray(5)=>false + +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** + +//2-Write a JavaScript function to get the first n element of an array. +//ex first([1,2,3],1)=>[1] +// first([1,2,3,4]2)=>[1,2] + +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** + +//3- Write a JavaScript function to convert an object into a list of `[key, value]` pairs +//ex: convert({name:'ahmed',age:20})=>[['name','ahmed'],['age', 20]] + +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** From 1d98b594a1be2c47643442b192b76038380f4c65 Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Mon, 23 Mar 2020 10:10:22 +0100 Subject: [PATCH 23/41] warmUp9 done --- warmUp9.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 warmUp9.js diff --git a/warmUp9.js b/warmUp9.js new file mode 100644 index 0000000..2047e01 --- /dev/null +++ b/warmUp9.js @@ -0,0 +1,50 @@ +// Style your code and explain it step by step before jumping to code :D +// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ + +//1. Write a JavaScript function to check whether an `input` is an array or not +// ex isArray([1,2])=>true +// isArray(5)=>false +// i used the isArray method to determine whether the passed value is an Array or not +function isArray(arr) { + return (Array.isArray(arr) ); +} + +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** + +//2-Write a JavaScript function to get the first n element of an array. +//ex first([1,2,3],1)=>[1] +// first([1,2,3,4]2)=>[1,2] +// i used a for loop for my new array to put every element in the passed array to my new array until i reach the index num-1 +function first (array,num) { + var arr = [] ; + for(var i = 0 ; i < num ; i++) { + arr[i] = array[i] ; + } + return arr ; +} + +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** + +//3- Write a JavaScript function to convert an object into a list of `[key, value]` pairs +//ex: convert({name:'ahmed',age:20})=>[['name','ahmed'],['age', 20]] +// i used the Object.entries method to put every key and his value in a new array +function convert(obj) { + var arr = Object.entries(obj) + return arr; +} +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** From a6816108d0f3c2680560f0e5cbe1e66614e40ed0 Mon Sep 17 00:00:00 2001 From: hashem-buzer Date: Mon, 23 Mar 2020 11:23:31 +0100 Subject: [PATCH 24/41] =?UTF-8?q?warmUp9=20=E2=9C=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- warmUp9.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/warmUp9.js b/warmUp9.js index b05ef52..de8a0b0 100644 --- a/warmUp9.js +++ b/warmUp9.js @@ -5,6 +5,7 @@ // ex isArray([1,2])=>true // isArray(5)=>false +var isArray = array => (Array.isArray(array) ? true : false); // **************** git status **************** // **************** git add fileName.js **************** // **************** git status **************** @@ -15,6 +16,7 @@ //2-Write a JavaScript function to get the first n element of an array. //ex first([1,2,3],1)=>[1] // first([1,2,3,4]2)=>[1,2] +var first = (arr, n) => arr.splice(0, n); // **************** git status **************** // **************** git add fileName.js **************** From 0e47aea7be29872390744ebf393e4da84d716048 Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Mon, 23 Mar 2020 21:43:57 +0100 Subject: [PATCH 25/41] warmUp 10 --- warmUp10.js | 28 ++++++++++++++++++++++++++++ warmUp9.js | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 warmUp10.js diff --git a/warmUp10.js b/warmUp10.js new file mode 100644 index 0000000..0773bc6 --- /dev/null +++ b/warmUp10.js @@ -0,0 +1,28 @@ +// Style your code and explain it step by step before jumping to code :D +// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ + +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** + +// 1- Using recursion Write a JavaScript program to find the greatest common divisor (gcd) of two positive numbers. + +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** + +// 2-Write a function called sum that accepts two numbers as parameters, and sum them together but without suming them togther directly +//you can only add one at each summetion, you'll need to use recursion in this. + +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** diff --git a/warmUp9.js b/warmUp9.js index b05ef52..ae2bad8 100644 --- a/warmUp9.js +++ b/warmUp9.js @@ -14,7 +14,7 @@ //2-Write a JavaScript function to get the first n element of an array. //ex first([1,2,3],1)=>[1] -// first([1,2,3,4]2)=>[1,2] +// first([1,2,3,4],2)=>[1,2] // **************** git status **************** // **************** git add fileName.js **************** From 124d3650adfc28718830cb3fdab6976c1b676cc1 Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Tue, 24 Mar 2020 09:41:52 +0100 Subject: [PATCH 26/41] warmUp10 done --- warmUp10.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 warmUp10.js diff --git a/warmUp10.js b/warmUp10.js new file mode 100644 index 0000000..62410a0 --- /dev/null +++ b/warmUp10.js @@ -0,0 +1,49 @@ +// Style your code and explain it step by step before jumping to code :D +// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ + +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** + +// 1- Using recursion Write a JavaScript program to find the greatest common divisor (gcd) of two positive numbers. + +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** + +// in mathematics one of the methods to calculate the gcd of two numbers is to keep dividing the smallest number by the rest of the last division until the rest reach 0 +// then the last rest not equal to 0 will be the gcd ... thats what i did in this function i kept calling it again by putting num2 as first parameter +// and the rest of the last division as second parameter ... until i reach my condition (rest equal to 0) then i returned the last rest not equal to 0 + +function gcd (num1,num2) { + if (num1 % num2 === 0) { + return num2 + } + return gcd(num2, num1 % num2); +} + + +// 2-Write a function called sum that accepts two numbers as parameters, and sum them together but without suming them togther directly +//you can only add one at each summetion, you'll need to use recursion in this. + +// **************** git status **************** +// **************** git add fileName.js **************** +// **************** git status **************** +// **************** git commit -m "your message" **************** +// **************** git status **************** +// **************** git push origin master **************** + +// i used recursion in this function to decrease one from number 2 every time i call the function and add one to the result until num2 become equal to 0 +// then the result will be equal to num2 (by adding 1 , num2 times) before i added num1 to it ... to get num1 + num2 + +function sum(num1, num2) { + if (num2 === 0) + return num1 ; + return 1 + sum (num1,num2-1); +} \ No newline at end of file From 2e45991693dd03c59b3e2910a21acd7a97fa8a3a Mon Sep 17 00:00:00 2001 From: hashem-buzer Date: Wed, 25 Mar 2020 09:03:41 +0100 Subject: [PATCH 27/41] warmUp11 --- warmUp11.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 warmUp11.js diff --git a/warmUp11.js b/warmUp11.js new file mode 100644 index 0000000..902ecca --- /dev/null +++ b/warmUp11.js @@ -0,0 +1,8 @@ +// 1-Create arrays in the global scope consisting of strings that represent: +// -name of females in your class +// -name of males in your class +// -name of your class instructors + +// 2-write a function that takes an array as an argument and returns the element that is located in the middle of that array. + +// 3-Change all the numbers in the array to be multiplied by two for even indexes. From e462924cc75773280aeb32556782920c16791f3d Mon Sep 17 00:00:00 2001 From: Houda Rouaissi <35735199+HoudaRs@users.noreply.github.com> Date: Wed, 25 Mar 2020 09:10:20 +0100 Subject: [PATCH 28/41] Update warmUp5.js --- warmUp5.js | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/warmUp5.js b/warmUp5.js index d14047b..cb26cd6 100644 --- a/warmUp5.js +++ b/warmUp5.js @@ -3,33 +3,16 @@ // - returns whichever number is the greater (higher) number. // ex greaterNum(5, 10) => "The greater number of 5 and 10 is 10." -var greaterNum = (num1, num2) => { - return num1 > num2 ? num1 : num1 < num2 ? num2 : "equal"; -}; + // 2) Write a function named isEven using for loop that // - iterate from x to y. // - return array contain the even values, // ex: isEven(1,10) => [2,4,6,8,10] -var isEven = (x, y) => { - var array = []; - - for (var i = x; i < y; i++) { - i % 2 === 0 ? array.push(i) : null; - } - return array; -}; //3) write a function named sum that // - Use a while loop to add up the numbers from x to y. // ex sum(1,5) => 15 -var sum = (x, y) => { - var result = 0; - for (var i = x; i <= y; i++) { - result += i; - } - return result; -}; //4) Write a function named factorial that // - Use Recursion to calculate the factorial of a number @@ -37,10 +20,6 @@ var sum = (x, y) => { // - 5! = 5*4*3*2*1 = 120 // ex : factorial(5) => 120 -var factorial = n => { - return n === 0 ? 1 : n * factorial(n - 1); -}; - //5) write a function named decimals //- the function will format a number up to specified decimal places //- the function will return a string From 1e0ee781b93372bec856a5650f3ddd7d9aad5ca5 Mon Sep 17 00:00:00 2001 From: Houda Rouaissi <35735199+HoudaRs@users.noreply.github.com> Date: Wed, 25 Mar 2020 09:10:47 +0100 Subject: [PATCH 29/41] Update warmUp8.js --- warmUp8.js | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/warmUp8.js b/warmUp8.js index 62192ac..11e4be0 100644 --- a/warmUp8.js +++ b/warmUp8.js @@ -1,33 +1,8 @@ // 1 - Write a function named objKey that take an object as a parameter and returns an array containing the keys of the object // objKey({name:'ahmed',age:20}) ==> ['name','age'] -var objKey = obj => { - return Object.keys(obj); -}; + // 2 - Write a function named objLength to get the length of a JavaScript object // objLength({name:'ahmed',age:20}) ==> 2 -var objLength = obj => { - return Object.keys(obj).length; -}; // 3 - Write a function named objSort to sort an array of JavaScript objects based on the id // objSort([{id:2,value:50},{id:0,value:70},{id:1,value:40}]) ==> [{id:0,value:70},{id:1,value:40},{id:2,value:50}] - -var objSort = (array, track, newArr) => { - var track = track || 0; - var newArr = newArr || []; - - if (newArr.length === array.length) { - return newArr; - } - - for (var i = 0; i < array.length; i++) { - console.log(array[i].id, "the array element"); - - if (array[i].id === track) { - console.log(array[i], "the if array[i].id"); - newArr.push(array[i]); - } - } - - return objSort(array, ++track, newArr); -}; From 542e878735fb7d381c1d2089efdfe92c5a97bbd6 Mon Sep 17 00:00:00 2001 From: Houda Rouaissi <35735199+HoudaRs@users.noreply.github.com> Date: Wed, 25 Mar 2020 09:11:12 +0100 Subject: [PATCH 30/41] Update warmUp4.js --- warmUp4.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/warmUp4.js b/warmUp4.js index 5f4dcd3..6db784a 100644 --- a/warmUp4.js +++ b/warmUp4.js @@ -1,12 +1,7 @@ // 1-write a function that returns the product of any number by 3. -function product(number) { - return number * 3; -} // 2-complete the following function multiply to return the result of multiplying of x and y -function multiply(n1, n2) { - return n1 * n2; -} + // 3-complete the following function that Convert Fahrenheit to Celsius if the module for converting is // (5/9) * (fahrenheit-32); From aeafcae099c109352537fd354383f16c4f73e1b7 Mon Sep 17 00:00:00 2001 From: Houda Rouaissi <35735199+HoudaRs@users.noreply.github.com> Date: Wed, 25 Mar 2020 09:15:52 +0100 Subject: [PATCH 31/41] Update warmUp7.js --- warmUp7.js | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/warmUp7.js b/warmUp7.js index 3cf26ad..2bcd0d4 100644 --- a/warmUp7.js +++ b/warmUp7.js @@ -7,28 +7,7 @@ //ex: helloWorld('fr') ==> 'Bonjour tout le monde' // helloWorld('es') ==> 'Hola, Mundo' // helloWorld('') ==> 'Hello, World' -var helloWorld = lang => { - var lang = lang.toLowerCase(); - return lang === "" - ? "Hello, World" - : lang === "fr" - ? "Bonjour tout le monde" - : lang === "es" - ? "Hola, Mundo" - : lang === "ar" - ? "صباح الخير" - : null; -}; //3- write a function to Reverse an array without use array.reverse() method: // ex: reverseArray([1,2,3]) ==> [3,2,1] -var reverse = arr => { - var result = []; - - for (var i = arr.length - 1; i >= 0; i--) { - result.push(arr[i]); - } - - return result; -}; From 653380f0d3cfd04593d0015d0f827730dc1ad99a Mon Sep 17 00:00:00 2001 From: Houda Rouaissi <35735199+HoudaRs@users.noreply.github.com> Date: Wed, 25 Mar 2020 09:16:42 +0100 Subject: [PATCH 32/41] Update warmUp9.js --- warmUp9.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/warmUp9.js b/warmUp9.js index 0536008..b2218c3 100644 --- a/warmUp9.js +++ b/warmUp9.js @@ -5,7 +5,6 @@ // ex isArray([1,2])=>true // isArray(5)=>false -var isArray = array => (Array.isArray(array) ? true : false); // **************** git status **************** // **************** git add fileName.js **************** // **************** git status **************** @@ -15,12 +14,8 @@ var isArray = array => (Array.isArray(array) ? true : false); //2-Write a JavaScript function to get the first n element of an array. //ex first([1,2,3],1)=>[1] -<<<<<<< HEAD // first([1,2,3,4]2)=>[1,2] -var first = (arr, n) => arr.splice(0, n); -======= -// first([1,2,3,4],2)=>[1,2] ->>>>>>> 0e47aea7be29872390744ebf393e4da84d716048 + // **************** git status **************** // **************** git add fileName.js **************** From eedf4d1da29beb7f6472f832fb846002ed7197b5 Mon Sep 17 00:00:00 2001 From: Houda Rouaissi <35735199+HoudaRs@users.noreply.github.com> Date: Wed, 25 Mar 2020 09:18:50 +0100 Subject: [PATCH 33/41] warmUp 6 --- warmUp6.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/warmUp6.js b/warmUp6.js index db0d319..c481fcd 100644 --- a/warmUp6.js +++ b/warmUp6.js @@ -2,17 +2,11 @@ // Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ // 1-Define a function called myTrueFun that returns true whenever its called. -var myTrueFun = () => { - return true; -}; + // 2- Define a function called color in which returns true if type of the input is string and returns false otherwise. -var color = input => { - return typeof input === "string" ? true : false; -}; + // 3-Write a JavaScript function that accepts a number as a parameter and check if the number is prime or not. // 4-write a function that accepts two numbers as parameters and returns true if the two parameters have the same value , false if not -var same = (number1, number2) => { - return number1 === number2 ? true : false; -}; + From 2fbd6e787e788738220a5a2b2e251fcd52894d11 Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Wed, 25 Mar 2020 10:09:11 +0100 Subject: [PATCH 34/41] warmUp11 done --- warmUp11.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 warmUp11.js diff --git a/warmUp11.js b/warmUp11.js new file mode 100644 index 0000000..854748d --- /dev/null +++ b/warmUp11.js @@ -0,0 +1,23 @@ +// 1-Create arrays in the global scope consisting of strings that represent: +// -name of females in your class +// -name of males in your class +// -name of your class instructors +var femalesName = ["Ranoua", "Khaoula", "Reem", "Hiba", "Amal"]; +var malesName = ["Bassem", "Charaf", "Ahmed", "Moez", "Oussama", "Firas"] +var classInstructors = ["Farouk", "Omar", "Hashem", "Seif", "Houda", "Dhia", "Insaf"] + +// 2-write a function that takes an array as an argument and returns the element that is located in the middle of that array. +function middle (array) { + var x = array.length ; + if (x % 2 === 0) { + return false + } + return array[(x-1)/2]; +} +// 3-Change all the numbers in the array to be multiplied by two for even indexes. +function multiplyEven (array) { + for (var i = 0 ; i < array.length ; i+=2) { + array[i] *= 2 ; + } + return array ; +} \ No newline at end of file From 61b0662bb14ae4fe1668c5e0f12461a2bba0362d Mon Sep 17 00:00:00 2001 From: Mohamed-Dhia <56113399+mohamed-Dhia@users.noreply.github.com> Date: Thu, 26 Mar 2020 09:02:12 +0100 Subject: [PATCH 35/41] warmUp12 --- warmUp12.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 warmUp12.js diff --git a/warmUp12.js b/warmUp12.js new file mode 100644 index 0000000..f4dc26e --- /dev/null +++ b/warmUp12.js @@ -0,0 +1,6 @@ +// 1-Write a function that takes a string as an input and returns the reverse of each letter +//followed by a number starting from zero(solve it using while loop). +// example: reverseStr('hello'); "o0l1l2e3h4" + +// 2-write a function that takes array of strings and returns an array of the strings that have the same length +// example : ['hi','hello','welcome','hy'] == > ["hi","hy"] From b4507e76f65e0b36afe4a3346e042d7ec0acd2c6 Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Thu, 26 Mar 2020 10:18:16 +0100 Subject: [PATCH 36/41] warmUp12 done --- warmUp12.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 warmUp12.js diff --git a/warmUp12.js b/warmUp12.js new file mode 100644 index 0000000..99a0ca4 --- /dev/null +++ b/warmUp12.js @@ -0,0 +1,31 @@ +// 1-Write a function that takes a string as an input and returns the reverse of each letter +//followed by a number starting from zero(solve it using while loop). +// example: reverseStr('hello'); "o0l1l2e3h4" +function reverseStr(str) { + var array = [] ; + var j = 0 ; + var arr = str.split('') + var i = arr.length - 1 ; + while (i >= 0 ) { + array[j] = arr[i] + array[j+1] = j/2 ; + i--; + j += 2; + } + return array.join('') ; +} +// 2-write a function that takes array of strings and returns an array of the strings that have the same length +// example : ['hi','hello','welcome','hy'] == > ["hi","hy"] +function sameLength (arr){ + var array = [] ; + for (var i = 0 ; i < arr.length ; i++) { + for (var j = i + 1 ; j < arr.length ; j++) { + if ( arr[i].length === arr[j].length ) { + array[0] = arr[i]; + array.push(arr[j]); + + } + } + } + return array ; +} From 344f7894548bc89b02d026c11b141ac1d7b023ce Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Fri, 27 Mar 2020 09:06:39 +0100 Subject: [PATCH 37/41] warmUp 13 --- warmUp13.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 warmUp13.js diff --git a/warmUp13.js b/warmUp13.js new file mode 100644 index 0000000..12ff169 --- /dev/null +++ b/warmUp13.js @@ -0,0 +1,12 @@ +// Style your code and explain it step by step before jumping to code :D +// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ + +// 1-implement the function mult that takes a single parameter n, and computes the multiplication of all integers up to n +//starting from 0, e.g.: +// mult(3); // => 6 +// mult(4); // => 24 + +// 2- Use a while loop to build a single string with the numbers 1 through n +// separated by the number next to the current number. +//Have it return the new string. +// eg= 1 2 2 3 3 4 4 5 5 6 6 ... From abdfde3700c677e1d97d6eed7e593edc25499750 Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Fri, 27 Mar 2020 09:52:46 +0100 Subject: [PATCH 38/41] warmUp13 done --- warmUp13.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 warmUp13.js diff --git a/warmUp13.js b/warmUp13.js new file mode 100644 index 0000000..c7e54d1 --- /dev/null +++ b/warmUp13.js @@ -0,0 +1,41 @@ +// Style your code and explain it step by step before jumping to code :D +// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ + +// 1-implement the function mult that takes a single parameter n, and computes the multiplication of all integers up to n +//starting from 0, e.g.: +// mult(3); // => 6 +// mult(4); // => 24 + +// i used a for loop so the counter variable i declared keeps increasing by 1 and multply all integers from 1 up to n + +function mult (n) { + if (n === 0) { + return 0 ; + } + var total = 1 ; + for (var i = 1 ; i <= n ; i++) { + total *= i + } + return total ; +} + +// 2- Use a while loop to build a single string with the numbers 1 through n +// separated by the number next to the current number. +//Have it return the new string. +// eg= 1 2 2 3 3 4 4 5 5 6 6 ... + +// i declared an array to put my values in it ... then i used join(' ') to transform it to a string with space between each two characters +//i added two counter variables j and i ... j moves from index to index+2 ... and i the value assigned to each index +function buildString (n) { + var i = 1 ; + var j = 1 ; + var arr = [] ; + arr[0] = 1 ; + while (i < n) { + arr[j] = i + 1 ; + arr[j+1] = i + 1 ; + i++; + j += 2 ; + } + return arr.join(' ') ; +} \ No newline at end of file From f7116e6bad742d738191118e716e7a8f26aa143c Mon Sep 17 00:00:00 2001 From: Seif-Miehiar Date: Sat, 28 Mar 2020 09:01:39 +0100 Subject: [PATCH 39/41] warmUp 14 --- warmUp14.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 warmUp14.js diff --git a/warmUp14.js b/warmUp14.js new file mode 100644 index 0000000..012d499 --- /dev/null +++ b/warmUp14.js @@ -0,0 +1,9 @@ +// Style your code and explain it step by step before jumping to code :D +// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ + +//create a function isSubset that should take two arrays and determine whether the second array is a subset of the first array. +//For example: + +// array: [ 1, 2, 3, 4 ], sub:[ 2, 3, 4 ] => true +// array: [ 2, 2, 2, 3, 4 ], sub:[ 2, 4, 3 ] => true +// array: [ 2, 3, 3, "a" ], sub:[ 3, 3, 3, "a" ] => false From e798081435fe7ecc6c54dca9778e40396f9bf70f Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Sat, 28 Mar 2020 10:19:22 +0100 Subject: [PATCH 40/41] warmUp14 solved --- warmUp14.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 warmUp14.js diff --git a/warmUp14.js b/warmUp14.js new file mode 100644 index 0000000..5b1cac7 --- /dev/null +++ b/warmUp14.js @@ -0,0 +1,27 @@ +// Style your code and explain it step by step before jumping to code :D +// Read carefully, focus and test your code :) ... /\ HaPPy HaCkInG /\ + +//create a function isSubset that should take two arrays and determine whether the second array is a subset of the first array. +//For example: + +// array: [ 1, 2, 3, 4 ], sub:[ 2, 3, 4 ] => true +// array: [ 2, 2, 2, 3, 4 ], sub:[ 2, 4, 3 ] => true +// array: [ 2, 3, 3, "a" ], sub:[ 3, 3, 3, "a" ] => false + +// i used 2 loop 1 for array and 1 for sup to check if each element in sub is found in array ... if its found i delete it and i exit the loop with (break) +// if the loop was not broken thats mean the element was not found in array so i return false ... otherwise i return true +function isSubset (array,sub) { + var j = 0 ; + for (var i = 0 ; i < sub.length ; i++) { + for (var j = 0 ; j < array.length ; j++) { + if ( sub[i] === array[j]) { + delete array[j] ; + break; + } + } + if (j === array.length) { + return false + } + } + return true +} \ No newline at end of file From dd8f7c907c09e78ab760f45b3c1ccbad6ed25ad2 Mon Sep 17 00:00:00 2001 From: MohamedAmine-Oueslati Date: Sat, 28 Mar 2020 10:22:24 +0100 Subject: [PATCH 41/41] warmUp14 solved --- warmUp14.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/warmUp14.js b/warmUp14.js index 5b1cac7..3666042 100644 --- a/warmUp14.js +++ b/warmUp14.js @@ -8,7 +8,7 @@ // array: [ 2, 2, 2, 3, 4 ], sub:[ 2, 4, 3 ] => true // array: [ 2, 3, 3, "a" ], sub:[ 3, 3, 3, "a" ] => false -// i used 2 loop 1 for array and 1 for sup to check if each element in sub is found in array ... if its found i delete it and i exit the loop with (break) +// i used 2 loops 1 for array and 1 for sub to check if each element in sub is found in array ... if its found i delete it and i exit the loop with (break) // if the loop was not broken thats mean the element was not found in array so i return false ... otherwise i return true function isSubset (array,sub) { var j = 0 ;