Skip to content

Instantly share code, notes, and snippets.

@cfinn16
Created April 12, 2019 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfinn16/10fb401f10f789206ee2b0369a9cec91 to your computer and use it in GitHub Desktop.
Save cfinn16/10fb401f10f789206ee2b0369a9cec91 to your computer and use it in GitHub Desktop.
Bluecore Coding Assignment
//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