Created
April 12, 2019 16:39
-
-
Save cfinn16/10fb401f10f789206ee2b0369a9cec91 to your computer and use it in GitHub Desktop.
Bluecore Coding Assignment
This file contains 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
//First Problem Solution | |
const consecutiveOddOrEvenDigits = (num) => { | |
let newArr = [] | |
const digits = num.toString().split('') | |
const numArr = digits.map(Number) | |
console.log(numArr) | |
while (numArr.length > 0) { | |
let j = 1 | |
while (numArr[0] % 2 === numArr[j] % 2) { | |
j++ | |
} | |
newArr.push(numArr.splice(0, j)) | |
} | |
return newArr.map(arr => { | |
return parseInt(arr.map(int => { | |
return int.toString() | |
}).join('')) | |
}) | |
} | |
//Second Problem Solution | |
const squaredDigitsSequence = (num) => { | |
const newResult = (number) => { | |
let result = 0 | |
const digits = number.toString().split('') | |
const testArr = digits.map(Number) | |
testArr.forEach(int => { | |
result += Math.pow(int, 2) | |
}) | |
return result | |
} | |
const checkSequence = (number) => { | |
let currentResult = newResult(number) | |
if (results.includes(currentResult)) { | |
results.push(currentResult) | |
} else { | |
results.push(currentResult) | |
console.log(results) | |
let number = currentResult | |
checkSequence(number) | |
} | |
} | |
const results = [] | |
results.push(num) | |
let testNum = num | |
checkSequence(testNum) | |
return results.length | |
} | |
//Third Solution | |
//Ran out of time before I could incorporate solution if amount is a percentage. Would need to write helper function that converts that to seconds to be able to fully complete problem | |
const bingeWatching = (timeElapsed, duration, action, amount) => { | |
const timeStrToSeconds = (str) => { | |
newArr = str.split(':').map(Number) | |
return (newArr[0] * 3600) + (newArr[1] * 60) + newArr[2] | |
} | |
const secondsToTimeStr = (seconds) => { | |
const hours = Math.floor(seconds / 3600) | |
const minutes = (seconds % 3600) / 60 | |
const remainingSeconds = seconds - (hours * 3600) - (minutes * 60) | |
return "" + hours + ":" + minutes + ":" + remainingSeconds | |
} | |
if (action === "Report Progress") { | |
return timeStrToSeconds(timeElapsed) / timeStrToSeconds(duration) * 100 | |
} else if (action === "Rewind") { | |
if (typeof amount === "string") { | |
const newTime = timeStrToSeconds(timeElapsed) - timeStrToSeconds(amount) | |
console.log(newTime) | |
if (newTime < 0) { | |
return "00:00:00" | |
} else { | |
return secondsToTimeStr(newTime) | |
} | |
} | |
} else if (action === "Fast Forward") { | |
if (typeof amount === "string") { | |
const newTime = timeStrToSeconds(timeElapsed) + timeStrToSeconds(amount) | |
if (newTime > timeStrToSeconds(duration)) { | |
return "Movie Finished" | |
} else { | |
return secondsToTimeStr(newTime) | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment