Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

questions solved #5

Open
wants to merge 48 commits into
base: MohamedAmine-Oueslati
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ce48543
questions solved
MohamedAmine-Oueslati Mar 13, 2020
9a3bc1a
warmUp2
Seif-Miehiar Mar 14, 2020
b6d9181
updated
Seif-Miehiar Mar 14, 2020
286372f
Merge branch 'master' of https://github.com/RBK-RebootKampTunisiaCoho…
MohamedAmine-Oueslati Mar 14, 2020
5cd3532
questions solved
MohamedAmine-Oueslati Mar 14, 2020
87d1ed2
warmUp3 is pushed
Seif-Miehiar Mar 16, 2020
68e0a89
questions solved
MohamedAmine-Oueslati Mar 16, 2020
4ab3967
warmUp 4
Seif-Miehiar Mar 16, 2020
6e144bf
questions solved
MohamedAmine-Oueslati Mar 17, 2020
b0ec828
warmUp5
Seif-Miehiar Mar 18, 2020
bb8f600
warmup5
Seif-Miehiar Mar 18, 2020
1610c21
warmUp5 done
MohamedAmine-Oueslati Mar 18, 2020
7e2c034
warmUp 5✔
Hashem-Buzer Mar 18, 2020
a293eee
warmUp6
Seif-Miehiar Mar 18, 2020
8b5ecdb
Merge branch 'master' of https://github.com/RBK-RebootKampTunisiaCoho…
Hashem-Buzer Mar 19, 2020
5fe6b78
warmUp6 done
MohamedAmine-Oueslati Mar 19, 2020
49a776a
warmUp7
Seif-Miehiar Mar 19, 2020
6ec5290
warmUp7 done
MohamedAmine-Oueslati Mar 20, 2020
83d2003
Merge branch 'master' of https://github.com/RBK-RebootKampTunisiaCoho…
Hashem-Buzer Mar 20, 2020
33c87b6
solved
Hashem-Buzer Mar 20, 2020
e30243f
warmUp7 is solved
Hashem-Buzer Mar 20, 2020
69e466b
warmUp 8
Seif-Miehiar Mar 21, 2020
11f895e
Merge branch 'master' of https://github.com/RBK-RebootKampTunisiaCoho…
Hashem-Buzer Mar 21, 2020
c12c258
warmUp8 done
MohamedAmine-Oueslati Mar 21, 2020
943001a
warmUp8 ✔
Hashem-Buzer Mar 21, 2020
688273d
warmUp 9
Seif-Miehiar Mar 22, 2020
6c83c81
Merge branch 'master' of https://github.com/RBK-RebootKampTunisiaCoho…
Hashem-Buzer Mar 23, 2020
1d98b59
warmUp9 done
MohamedAmine-Oueslati Mar 23, 2020
a681610
warmUp9 ✔
Hashem-Buzer Mar 23, 2020
0e47aea
warmUp 10
Seif-Miehiar Mar 23, 2020
124d365
warmUp10 done
MohamedAmine-Oueslati Mar 24, 2020
651ca42
test the pull request
Hashem-Buzer Mar 24, 2020
2e45991
warmUp11
Hashem-Buzer Mar 25, 2020
e462924
Update warmUp5.js
Houda-Rouaissi Mar 25, 2020
1e0ee78
Update warmUp8.js
Houda-Rouaissi Mar 25, 2020
542e878
Update warmUp4.js
Houda-Rouaissi Mar 25, 2020
aeafcae
Update warmUp7.js
Houda-Rouaissi Mar 25, 2020
653380f
Update warmUp9.js
Houda-Rouaissi Mar 25, 2020
eedf4d1
warmUp 6
Houda-Rouaissi Mar 25, 2020
2fbd6e7
warmUp11 done
MohamedAmine-Oueslati Mar 25, 2020
61b0662
warmUp12
mohamed-Dhia Mar 26, 2020
b4507e7
warmUp12 done
MohamedAmine-Oueslati Mar 26, 2020
344f789
warmUp 13
Seif-Miehiar Mar 27, 2020
abdfde3
warmUp13 done
MohamedAmine-Oueslati Mar 27, 2020
f7116e6
warmUp 14
Seif-Miehiar Mar 28, 2020
e798081
warmUp14 solved
MohamedAmine-Oueslati Mar 28, 2020
dd8f7c9
warmUp14 solved
MohamedAmine-Oueslati Mar 28, 2020
dd8e3af
warmUp15 solved
MohamedAmine-Oueslati Mar 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions warmUp1.js
Original file line number Diff line number Diff line change
@@ -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) ;
55 changes: 55 additions & 0 deletions warmUp10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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 ****************

<<<<<<< HEAD
// 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);
}


=======
>>>>>>> f7116e6bad742d738191118e716e7a8f26aa143c
// 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 ****************
<<<<<<< HEAD

// 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);
}
=======
>>>>>>> f7116e6bad742d738191118e716e7a8f26aa143c
30 changes: 30 additions & 0 deletions warmUp11.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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
<<<<<<< HEAD
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 ;
}
=======

// 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.
>>>>>>> f7116e6bad742d738191118e716e7a8f26aa143c
37 changes: 37 additions & 0 deletions warmUp12.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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"
<<<<<<< HEAD
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 ;
}
=======

// 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"]
>>>>>>> f7116e6bad742d738191118e716e7a8f26aa143c
47 changes: 47 additions & 0 deletions warmUp13.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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

<<<<<<< HEAD
// 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 ;
}

=======
>>>>>>> f7116e6bad742d738191118e716e7a8f26aa143c
// 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 ...
<<<<<<< HEAD

// 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(' ') ;
}
=======
>>>>>>> f7116e6bad742d738191118e716e7a8f26aa143c
30 changes: 30 additions & 0 deletions warmUp14.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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
<<<<<<< HEAD

// 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 ;
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
}
=======
>>>>>>> f7116e6bad742d738191118e716e7a8f26aa143c
27 changes: 27 additions & 0 deletions warmUp15.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 1-using + operator combine your partner first and last name .
var firstName = 'Wala' ;
var lastName = 'Nour' ;
var fullName = firstName + ' ' + lastName ;

// 2-find if the number 13 is a multiple of 3 or not.
13 % 3 === 0 ? "13 is a multiple of 3" : "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]
var arr = [13,14,13,15,16,17,19,13,16,15] ;
function average(arr) {
var sum = 0 ;
for (var i = 0 ; i < arr.length ; i++){
sum += arr[i] ;
}
return sum / arr.length ;
}

average(arr)

// 4-calculate your age in seconds.
var age = 28
function ageInSeconds (age) {
return age * 365 * 24 * 60 * 60 ;
}

ageInSeconds (age)
45 changes: 45 additions & 0 deletions warmUp2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 1 - Complete the function cube that returns the cube of x:

function cube(x) {
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) {
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) {
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
// repeatString('dog', 0); // => ''
// repeatString('dog', 1); // => 'dog'
// repeatString('dog', 2); // => 'dog' + 'dog' => 'dogdog'
// repeatString('dog', 3); // => 'dog' + 'dog' + 'dog' => 'dogdogdog'

function repeatString(str, count) {
if (count === 0) {
return '' ;
}
count-- ;
return str += repeatString(str, count)
}
87 changes: 87 additions & 0 deletions warmUp3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 1 - Write functions larger and smaller that each accept two strings as arguments, and return the larger and smaller strings, respectively
<<<<<<< HEAD

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);
}

=======

// 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'
>>>>>>> f7116e6bad742d738191118e716e7a8f26aa143c

// 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
//

<<<<<<< HEAD
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 ;
}
=======
// 4- Write a function shortestWord that works like longestWord, but returns the shortest word instead.
>>>>>>> f7116e6bad742d738191118e716e7a8f26aa143c
Loading