From bf4ed2fdff69be8be23fd54f52ff663e89e1c165 Mon Sep 17 00:00:00 2001 From: Ammar Sammour <35445761+Ammar-64@users.noreply.github.com> Date: Sat, 1 May 2021 03:10:09 +0300 Subject: [PATCH 1/2] Revert "kutay-ayshe-objectExercise" --- class-9-js-object/kutay-ayshe/index.html | 23 ---------- class-9-js-object/kutay-ayshe/script.js | 54 ------------------------ class-9-js-object/kutay-ayshe/style.css | 0 3 files changed, 77 deletions(-) delete mode 100644 class-9-js-object/kutay-ayshe/index.html delete mode 100644 class-9-js-object/kutay-ayshe/script.js delete mode 100644 class-9-js-object/kutay-ayshe/style.css diff --git a/class-9-js-object/kutay-ayshe/index.html b/class-9-js-object/kutay-ayshe/index.html deleted file mode 100644 index 6c1ba61..0000000 --- a/class-9-js-object/kutay-ayshe/index.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - repl.it - - - -
- - -
-
- - -
-
- -
- - - \ No newline at end of file diff --git a/class-9-js-object/kutay-ayshe/script.js b/class-9-js-object/kutay-ayshe/script.js deleted file mode 100644 index bb5606b..0000000 --- a/class-9-js-object/kutay-ayshe/script.js +++ /dev/null @@ -1,54 +0,0 @@ -// Entries should be an *array of objects*. -const entries = []; - -document.querySelector(".submitButton").addEventListener('click', (e) => { - /* - * When the button is clicked, you should collect the first name, - * last name, and bio and store them in an object with three keys: - * first name, last name, and bio. - * - * You should then add this object to the entries array. - */ - - e.preventDefault(); - - let firstName = document.querySelector(".firstName").value; - let lastName = document.querySelector(".lastName").value; - let bio = document.querySelector(".bio").value; - - - const object = { - firstName : firstName, - lastName : lastName, - bio : bio, - }; - - entries.push(object); - -// This function is called for you. You also have to implement it. - - renderPeople(entries); - -}); - -// This function should modify the element with the .output class -// to render `people` however you want. -// -// THIS FUNCTION SHOULD NOT USE THE VARIABLE `entries`! -function renderPeople(people) { - - - const displayDiv = document.querySelector(".output"); - displayDiv.innerHTML = " "; - - - for (let i = 0; i Date: Fri, 21 May 2021 23:06:47 +0300 Subject: [PATCH 2/2] this is the new one --- .DS_Store | Bin 12292 -> 14340 bytes .../map-exercise/README.md | 38 ++++++++ .../map-exercise/index.js | 50 ++++++++++ .../map-reduce-exercises/README.md | 65 +++++++++++++ .../map-reduce-exercises/index.js | 88 ++++++++++++++++++ 5 files changed, 241 insertions(+) create mode 100644 class-13-map-reduce/kutay-moulham-map-reduce/map-exercise/README.md create mode 100644 class-13-map-reduce/kutay-moulham-map-reduce/map-exercise/index.js create mode 100644 class-13-map-reduce/kutay-moulham-map-reduce/map-reduce-exercises/README.md create mode 100644 class-13-map-reduce/kutay-moulham-map-reduce/map-reduce-exercises/index.js diff --git a/.DS_Store b/.DS_Store index ed1415581bce76c430b6f30d8ec82ec91170332d..f43ec043f652a7add3875c25878f44608fa85dfa 100644 GIT binary patch delta 767 zcmb7?PiqrV6vfZ{DV-!^Iua*M4AmipZk%W)e{2O8T5usq2`B_tZ6;}rI?jYlV!$Bj zqPP!lEByq5==%ch^b5Ea1lO*`MZNDWYBDQ*!@T==oH=uTmwR$>GH?JWyW^e*ROx8Y zE2?GE_6BgwxpPCQ%v;;6>gp_`U(3FHI1Ga*d_n>x9`K7sUjJ}h(NYRs&@wXeif@@e zG^Ow{x2Io?;Nuw%(Z%R~5Ow_^@=0g`>Q}1Q*_mBr#|4`|UJn&(S)u%5zwHh7u4wbm zg*|n16)(_14-fE^OkX9$8x$$a?v%>hEq$X@yQ*@Dn@(G0U+nD6BeDtwiD^HgI3o(w zUv^Lh)#;gBbOJ7uCZIpY@+%LubB7Lw^hB6Qw=qJ2N2wx&2~Pn@o-^SpO>+s;I#~#; z0o5S|>tRfa!(|)X6>u`yf4TURcpy8@o|o*Ew2{7$X05z`#V}GvYTqhMr}f&l>v)ak zYuB0H+NrtDO|QYMa&z{NITr_l_|_A2jq{dG&?h=U7^6+R0g*-t%J+XMRe&FqAL-oE zTN=yhTfAw#Rp+Dc#TD5`R5MiXEeKDf z1~-s)MRv}{i|?5y^PA}EfE0jiZh+8WM*s;XAQudPY>;O_Y78dlm`vOpp}w0D*%|;1 Cmp0n~ diff --git a/class-13-map-reduce/kutay-moulham-map-reduce/map-exercise/README.md b/class-13-map-reduce/kutay-moulham-map-reduce/map-exercise/README.md new file mode 100644 index 0000000..27e141b --- /dev/null +++ b/class-13-map-reduce/kutay-moulham-map-reduce/map-exercise/README.md @@ -0,0 +1,38 @@ +## Instructions For MAP Exercises + + +1) Write a function capitalize that takes a string and uses .map to return the same string in all caps. + +Example +``` +capitalize('whoop') // => 'WHOOP' +capitalize('oh hey gurl') // => "OH HEY GURL" +``` +``` +const capitalize = function(string){ + // code code code! +} +``` + +2) Now write a new function called swapCase that takes a string of words and uses .map and your newly written capitalize() function to return a string where every other word is in all caps. +Hint: look up Array.prototype.map on MDN and see what arguments the .map callback can take. + +example +``` +swapCase('hey gurl, lets javascript together sometime') // => "HEY gurl, LETS javascript TOGETHER sometime" +``` +``` +const swapCase = function(string){ + // Codeeeee +} +``` +3) Write a function shiftLetters that takes a string and uses .map to return an encoded string with each letter shifted down the alphabet by one. Hint: Use Look up the JS functions String.fromCharCode() and String.charCodeAt() and see if you can use Ascii code to accomplish this. + +``` +shiftLetters('hello') // => 'ifmmp' +shiftLetters('abcxyz') // => "bcdyz{" + +const shiftLetters = function(string){ + // code! +} +``` \ No newline at end of file diff --git a/class-13-map-reduce/kutay-moulham-map-reduce/map-exercise/index.js b/class-13-map-reduce/kutay-moulham-map-reduce/map-exercise/index.js new file mode 100644 index 0000000..ceee7fe --- /dev/null +++ b/class-13-map-reduce/kutay-moulham-map-reduce/map-exercise/index.js @@ -0,0 +1,50 @@ +function capitalize (string) { + const arrOfChar = string.split(""); + const solution = []; + + arrOfChar.map( char => { + solution.push(char.toUpperCase()); + }) + return solution.join(""); +} + +capitalize('alkdfjhglaksdf'); + +//----------------------------------------------------------------------------------- + +function swapCase (string) { + const arrOfWords = string.split(" "); + const solution = []; + + arrOfWords.map( (word, index) => { + if (index % 2 === 0){ + solution.push(capitalize(word)); + } + else { + solution.push(word); + } + }) + + console.log(solution.join(' ')); +} + +swapCase('hey gurl, lets javascript together sometime'); + +//----------------------------------------------------------------------------------- + +function shiftLetters (string) { + const arrOfChar = string.split(""); + const solution = []; + + arrOfChar.map( char => { + const newCharNumber = (char.charCodeAt(0) - 1); + const newChar = String.fromCharCode(newCharNumber); + solution.push(newChar); + }) + + return solution.join(""); +} + +shiftLetters ('moulham'); + +//----------------------------------------------------------------------------------- \ No newline at end of file diff --git a/class-13-map-reduce/kutay-moulham-map-reduce/map-reduce-exercises/README.md b/class-13-map-reduce/kutay-moulham-map-reduce/map-reduce-exercises/README.md new file mode 100644 index 0000000..11878aa --- /dev/null +++ b/class-13-map-reduce/kutay-moulham-map-reduce/map-reduce-exercises/README.md @@ -0,0 +1,65 @@ +## Get Sum of People's Budget + +Create the function that takes an array with objects and returns the sum of people's budgets. + +### Examples + + getBudgets([ + { name: "John", age: 21, budget: 23000 }, + { name: "Steve", age: 32, budget: 40000 }, + { name: "Martin", age: 16, budget: 2700 } + ]) ➞ 65700 + + getBudgets([ + { name: "John", age: 21, budget: 29000 }, + { name: "Steve", age: 32, budget: 32000 }, + { name: "Martin", age: 16, budget: 1600 } + ]) ➞ 62600 + + +## Instructions For Reduce and Map Exercises + +1) Write a function that takes a string and returns an object representing the character count for each letter. Use .reduce to build this object. + +Example +``` +countLetters('abbcccddddeeeee') // => {a:1, b:2, c:3, d:4, e:5} + +const countLetters = function(string){ + // your code here +}; +``` + +2) Write a function that takes a string and a target, and returns true or false if the target is present in the string. Use .reduce to accomplish this. + +Example +``` +isPresent('abcd', 'b') // => true +isPresent('efghi', 'a') // => false + +const isPresent = function(string, target) { + // your code +} +``` + +### PARTY WITH MAP AND REDUCE *AT THE SAME TIME* + +1) Write a function decode that will take a string of number sets and decode it using the following rules: +When each digit of each set of numbers is added together, the resulting sum is the ascii code for a single letter. +Convert each set of numbers into a letter and discover the secret message! +Try using map and reduce together to accomplish this task. +Example +``` +decode("361581732726247521644353 4161492813593986955 84654117917337166147521") // => "abc" +decode("584131398786538461382741 444521974525439455955 71415168525426614834414214 353238892594759181769 48955328774167683152 77672648114592331981342373 5136831421236 83269359618185726749 2554892676446686256 959958531366848121621517 4275965243664397923577 616142753591841179359 121266483532393851149467 17949678591875681") +// => "secret-message" + +const decode = function(string){ + // CODE PARTY +} +``` +Once you successfully write a decoding function, use it to decode this secret message! + +``` +"444689936146563731 2452966188592191874 52634311978613959924676311 4874232339 491973615889195397613151 64491375479568464397 2799868298847212752434 9464245911 84529438455334236247245 8131257451645317232949247 26471594451453281675411332 6631592725297745964837 616698332453173937881461 3311783543427862468268 385418321228899775431 4659867 73395213225525916984356 833792195426925124155181841 123388893 6941777837193213644325351 11353488912476869536954 61173937137292328237388335 5344692 452956158 31937616696951768494 584842118999165552436 8832121577139589884 15282516522883423742885 14713349724 6919979438697694 2252585676244745856486 5617683424485959291 547443594 2678324174797795449925 43753791352187862731151912 6875665565836721939262 35482977 84421878934473534291995 798457553821668942312 11114498238219156246883553 3599955 8831995953696776 8138759916933117676486 2388776737768787 37232647683297835458183 11318659392964788174775 683293746169875551252354 741545327395636643318531 38447974824822841161273 88768222547689886222 6345677462396774359 4942661761 1354569165 2553653936124138282 851786784517417366411515 42279319649497959785 5523951771 45941761289678527316294 37776454913244819275691 436669892715419465494342 682264111527 734681268219555989841131 882641896825571288724 382545666 12133138432672285179566156291 83644842221351483476411355532 9589336353993598224 184537669759184472427331 41851326945453796784 525783591 173773335961894524914465 47516715963756294236321 7296569497726217615 79487235 4931878519724923131437 31214731844284735237658435 1378458823933518466122 1241955123792435126557994 347427652476673662454 55596877477154112241923 9789414554758712319821 86228624276917113671233411 89659521 1352796469161477381192 69483824148396716861472 4766533634762298963245 5155973593459278561 1784478259974148659431 29583142566714785218623 244371427148584159487652 871836193187759591363 247956" +``` \ No newline at end of file diff --git a/class-13-map-reduce/kutay-moulham-map-reduce/map-reduce-exercises/index.js b/class-13-map-reduce/kutay-moulham-map-reduce/map-reduce-exercises/index.js new file mode 100644 index 0000000..94b0ca1 --- /dev/null +++ b/class-13-map-reduce/kutay-moulham-map-reduce/map-reduce-exercises/index.js @@ -0,0 +1,88 @@ +// function getBudgets (obj) { +// let sum = obj.reduce((acc, curr) => { +// return acc += curr.budget; +// }, 0) +// console.log(sum); +// } + +// getBudgets([ +// { name: "John", age: 21, budget: 23000 }, +// { name: "Steve", age: 32, budget: 40000 }, +// { name: "Martin", age: 16, budget: 2700 } +// ]); + +// //------------------------------------------------------------------------------- + +// function countLetters (string) { + +// const arrOfChars = string.split(''); + +// let object = arrOfChars.reduce((acc, curr) => { +// if (curr in acc) { +// acc[curr] ++; +// } +// else { +// acc[curr] = 1; +// } +// return acc; +// }, {}) // <=== DOES THIS CREATE A NEW OBJECT ? + +// console.log(object); + +// } + +// countLetters('abbcccddddeeeee'); + +//------------------------------------------------------------------------------- + +// function isPresent (str, targ) { + +// const arrOfChars = str.split(''); +// let bool = false; + +// let reducer = arrOfChars.reduce((acc, curr) => { +// if (curr === targ) { +// bool = true; +// } +// }) +// return bool; +// } + +// isPresent('efghi', 'a'); + +//------------------------------------------------------------------------------- + +// function decode (str) { +// const arrOfWord = str.split(" "); +// let arr = []; +// let numArr = []; +// let totalNumArr = []; +// let letters = []; + +// arrOfWord.map(item => { +// arr.push(item.split("")); +// }) + +// for (let i = 0; i < arr.length; i++){ +// const numbers = arr[i].map((n) => { +// return parseInt(n); +// }) +// numArr.push(numbers); +// } + +// for(let i = 0; i < numArr.length; i++) { +// const totalNums = numArr[i].reduce((acc, curr) => { +// acc+=curr; +// return acc; +// }, 0) +// totalNumArr.push(totalNums); +// } + +// const decoded = totalNumArr.map(item => { +// let letter = String.fromCharCode(item); +// letters.push(letter); +// }) +// return letters.join(''); +// } + +// decode ("444689936146563731 2452966188592191874 52634311978613959924676311 4874232339 491973615889195397613151 64491375479568464397 2799868298847212752434 9464245911 84529438455334236247245 8131257451645317232949247 26471594451453281675411332 6631592725297745964837 616698332453173937881461 3311783543427862468268 385418321228899775431 4659867 73395213225525916984356 833792195426925124155181841 123388893 6941777837193213644325351 11353488912476869536954 61173937137292328237388335 5344692 452956158 31937616696951768494 584842118999165552436 8832121577139589884 15282516522883423742885 14713349724 6919979438697694 2252585676244745856486 5617683424485959291 547443594 2678324174797795449925 43753791352187862731151912 6875665565836721939262 35482977 84421878934473534291995 798457553821668942312 11114498238219156246883553 3599955 8831995953696776 8138759916933117676486 2388776737768787 37232647683297835458183 11318659392964788174775 683293746169875551252354 741545327395636643318531 38447974824822841161273 88768222547689886222 6345677462396774359 4942661761 1354569165 2553653936124138282 851786784517417366411515 42279319649497959785 5523951771 45941761289678527316294 37776454913244819275691 436669892715419465494342 682264111527 734681268219555989841131 882641896825571288724 382545666 12133138432672285179566156291 83644842221351483476411355532 9589336353993598224 184537669759184472427331 41851326945453796784 525783591 173773335961894524914465 47516715963756294236321 7296569497726217615 79487235 4931878519724923131437 31214731844284735237658435 1378458823933518466122 1241955123792435126557994 347427652476673662454 55596877477154112241923 9789414554758712319821 86228624276917113671233411 89659521 1352796469161477381192 69483824148396716861472 4766533634762298963245 5155973593459278561 1784478259974148659431 29583142566714785218623 244371427148584159487652 871836193187759591363 247956") \ No newline at end of file