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

kutay-moulham-map-reduce #162

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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!
}
```
50 changes: 50 additions & 0 deletions class-13-map-reduce/kutay-moulham-map-reduce/map-exercise/index.js
Original file line number Diff line number Diff line change
@@ -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');

//-----------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -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"
```
Original file line number Diff line number Diff line change
@@ -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")
23 changes: 0 additions & 23 deletions class-9-js-object/kutay-ayshe/index.html

This file was deleted.

54 changes: 0 additions & 54 deletions class-9-js-object/kutay-ayshe/script.js

This file was deleted.

Empty file.