Last active
January 27, 2021 05:28
-
-
Save skawnkk/9f39379b9c07b7da593d753886a47519 to your computer and use it in GitHub Desktop.
week4
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
function diagonalDifference(arr) { | |
let line1 = 0; | |
let line2 = 0; | |
for (let i = 0; i < arr.length; i++) { | |
line1 += arr[i][i]; | |
line2 += arr[i][arr.length - 1 - i]; | |
} | |
let sum = Math.abs(line1 - line2); | |
return sum; | |
} |
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
function kangaroo(x1, v1, x2, v2) { | |
let boolean = "NO"; | |
for (let i = 0; i < 10000 && boolean === "NO"; i++) { | |
let kang1 = x1 + v1 * i; | |
let kang2 = x2 + v2 * i; | |
if (kang1 === kang2) boolean="YES"; | |
} | |
return boolean; | |
} |
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
function saveThePrisoner(n, m, s) { | |
let lucky = 0; | |
if (n > m) lucky = s + m - 1; | |
if (n <= m) { | |
if (m % n !== 0) lucky = m % n - 1 + s; | |
if (m % n === 0) { | |
if (s === 1) { | |
lucky = n + s - 1; | |
} else { | |
lucky = s - 1; | |
} | |
} | |
} | |
if (lucky > n) lucky -= n | |
return lucky; | |
} |
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
function timeConversion(s) { | |
let time = s.slice(0, 8); | |
let ampm = s.slice(8); | |
let parse = time.split(':').map(el => parseInt(el)); | |
if (ampm === 'PM') { | |
if (parse[0] === 12) { | |
parse[0] = 12 | |
} else { | |
((+parse[0] + 12) == 24) ? parse[0] = 0: parse[0] += 12 | |
} | |
} else { | |
if (parse[0] === 12) parse[0] = 0 | |
} | |
for (let i in parse) { | |
if (parse[i] < 10) { | |
parse[i] = '0' + parse[i] | |
} | |
} | |
return parse.join(':') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment