This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 147
Northwest Class 4 - Musa Yuksel - JS Core 2 - Week 3 #71
Open
musayuksel
wants to merge
4
commits into
CodeYourFuture:main
Choose a base branch
from
musayuksel:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| /********************************************* | ||
| * CodeWars homeworks | ||
| * https://www.codewars.com/collections/cyf-js-2-week-3 | ||
| ************************************************** */ | ||
|
|
||
|
|
||
|
|
||
|
|
||
| // 1 ********************************* | ||
| //Job Matching #2 | ||
| function match(job, candidates) { | ||
| // look at the candidate desiresEquity, if it's true => | ||
| //job equityMax has to be >0 & | ||
| // candidate currentLocation + desiredLocations have to include some job locationlocation | ||
| // else => just look at the locations | ||
| return candidates.filter(candidate =>{ | ||
| if(candidate.desiresEquity){ | ||
| console.log(job['equityMax'] > 0 && isIncludeLocation(candidate['currentLocation'],candidate['desiredLocations'],job['locations']),"WILLRETURN") | ||
| return job['equityMax'] > 0 && isIncludeLocation(candidate['currentLocation'],candidate['desiredLocations'],job['locations']) | ||
| } else { | ||
| return isIncludeLocation(candidate['currentLocation'],candidate['desiredLocations'],job['locations']); | ||
| } | ||
| }); | ||
|
|
||
| } | ||
| //this func will look at the locations | ||
| function isIncludeLocation (currLoc,desireLoc,jobLocation){ | ||
| const allLoc= desireLoc; | ||
| allLoc.push(currLoc);//current loc is String so put inside the array | ||
| return allLoc.some(elem=>{ | ||
| return jobLocation.includes(elem); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| // 2 ********************************* | ||
| //Split The Bill | ||
| function splitTheBill(obj) { | ||
| let counter=0; | ||
| let totalBill=0; | ||
| for(key in obj){//find avarage | ||
| counter++; | ||
| totalBill +=obj[key]; | ||
| } | ||
| const avarageBill = totalBill/counter; | ||
| for(key in obj){//find result and put inside in the object | ||
| obj[key] = Number((Math.round((obj[key] -avarageBill) * 100) / 100).toFixed(2)); | ||
| } | ||
| return obj; | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| // 3 ********************************* | ||
| //Convert the score | ||
| function scoreboard(str) { | ||
| const score ={one:1,two:2,three:3,four:4,five:5,six:6,seven:7,eight:8,nine:9, nil:0} | ||
| const scoreArr=[]; | ||
| for(key in score){ | ||
| if(str.indexOf(key)!==-1){ | ||
| scoreArr.push(score[key]); | ||
| scoreArr.push(str.indexOf(key)); | ||
| } | ||
| }//we took [1(score),3(index),nil(score),8] OR=> [4(score),8]==if score is same | ||
| if(scoreArr.length === 2){// score same return [2,2] | ||
| return [scoreArr[0],scoreArr[0]]; | ||
| } else if(scoreArr[1] < scoreArr[3]){ return [scoreArr[0],scoreArr[2]]; } | ||
| // look at the score index, return the correct order | ||
| else {return [scoreArr[2],scoreArr[0]];} | ||
| } | ||
|
|
||
|
|
||
| // 4 ********************************* | ||
| //Functional Addition | ||
| function add(n) { | ||
| return function(num){ | ||
| return num + n | ||
| };//declare new fucntion | ||
| } | ||
|
|
||
|
|
||
|
|
||
| // 5 ********************************* | ||
| //Scrabblemania | ||
| function wordscore(word) { | ||
| const letterPoints ={"a" : 1, "b" : 3,"c" : 3,"d" : 2, "e" : 1, "f" : 4,"g" : 2,"h" : 4,"i" : 1,"j" : 8,"k" : 5,"l" : 1,"m" : 3,"n" : 1,"o" : 1,"p" : 3,"q" : 10,"r" : 1,"s" : 1,"t" : 1,"u" : 1,"v" : 4, "w" : 4,"x" : 8,"y" : 4,"z" : 10} | ||
| //find total point of word(letter-by-letter) | ||
| //total*length | ||
| //if length 7 add 50 | ||
| let total = 0; | ||
| for(let i = 0; i < word.length; i ++){ | ||
| total += letterPoints[word.charAt(i)]; | ||
|
|
||
| } | ||
| total *= word.length; | ||
| if(word.length === 7){ | ||
| return total + 50; | ||
| } else{ | ||
| return total; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| // 6 ********************************* | ||
| //Who is the killer? | ||
| function killer(suspectInfo, dead) { | ||
| //LOOK AT ALL KEYS, | ||
| //IF ONE OF KEY HAS EVERY DEAD ELEMENT RETURN KEY | ||
| for(personSuspect in suspectInfo){ | ||
| if( | ||
| dead.every(person=> suspectInfo[personSuspect].includes(person)) | ||
| ) //if condition end | ||
| //if all dead person inside one of suspectPerson return True | ||
| {return personSuspect; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,36 @@ | ||
| function setAlarm() {} | ||
| function setAlarm() { | ||
| const h1 = document.getElementById('timeRemaining'); | ||
| let input = document.getElementById('alarmSet').value; | ||
| let intervalID= setInterval(() => { | ||
| const hour =Math.floor(input/60).toString().padStart(2, "0"); | ||
| //FOR MORE INFO ABOUT padStart() >>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart | ||
| const sec = (input % 60).toString().padStart(2, "0"); | ||
| h1.innerText =`Time Remaining: ${hour}:${sec}`; | ||
| if(input === 0) { | ||
| clearInterval(intervalID);//stop timer | ||
| doFlash();///EXTRA | ||
| playAlarm(); | ||
| } else { | ||
| input--; | ||
| } | ||
| }, 1000); | ||
| } | ||
| ///EXTRA | ||
| function doFlash(){ | ||
| const colors =['red','orange','green']; | ||
| let index =0; | ||
| //if stop alarm clicked stop flash else doflash | ||
| const flashID= setInterval(() => { | ||
| index++; | ||
| document.body.style.backgroundColor = colors[index%colors.length]; | ||
| }, 100); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [index%colors.length], this is smart |
||
| document.getElementById("stop").addEventListener("click", () => { | ||
| clearInterval(flashID); | ||
| document.body.style.backgroundColor = 'white'; | ||
|
|
||
| }); | ||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
|
|
@@ -22,4 +53,4 @@ function pauseAlarm() { | |
| audio.pause(); | ||
| } | ||
|
|
||
| window.onload = setup; | ||
| window.onload = setup; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know padStart() exists :) I am learning new things from your code as always. Great job