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
// JavaScript | |
strangeSequence = (num) => { | |
let numbers = [] | |
let count = 1 | |
while (numbers.indexOf(num) === -1) { | |
count++ | |
numbers.push(num) | |
num = ("" + num).split("").map(num => num * num).reduce((a, b) => a + b) | |
} |
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
// JavaScript | |
strangeSequence = (num) => { | |
let numbers = [] | |
let count = 1 | |
while (numbers.indexOf(num) === -1) { | |
count++ | |
numbers.push(num) | |
num = ("" + num).split("").map(num => num * num).reduce((a, b) => a + b) | |
} |
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
// JavaScript | |
// Question #1 | |
strangeSequence = (num) => { | |
let numbers = [] | |
let count = 1 | |
while (numbers.indexOf(num) === -1) { | |
count++ | |
numbers.push(num) |
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
// JavaScript | |
// Question #1 | |
strangeSequence = (num) => { | |
let numbers = [] | |
let count = 1 | |
while (numbers.indexOf(num) === -1) { | |
count++ | |
numbers.push(num) |
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
// JavaScript | |
// Question #1 | |
strangeSequence = (num) => { | |
let numbers = [] | |
let count = 1 | |
while (numbers.indexOf(num) === -1) { | |
count++ | |
numbers.push(num) |
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
Input: Initial State = [2, 3, 4, 5] | Unlock Code = [5, 4, 3, 2] | |
Output: Rotations required = 8 | |
Explanation : 1st ring is rotated 3 times as 2 => 3 => 4 => 5 | |
2nd ring is rotated 1 time as 3 => 4 | |
3rd ring is rotated 1 time as 4 => 3 | |
4th ring is rotated 3 times as 5 => 4 => 3 =>2 | |
Input: Initial State = [1, 9, 1, 9] | Unlock Code = [0, 0, 0, 0] | |
Output: Rotations Required = 4 | |
Explanation : 1st ring is rotated 1 time as as 1 => 0 |
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
combinationLock = (initialState, code) => { | |
// declare a variable to account for total turns | |
let totalTurns = 0; | |
// iterate over the initialState array | |
// this what the lock looks like when it's first handed to you | |
initialState.forEach((i, index) => { | |
// i is the value |
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
combinationLock = (initialState, code) => { | |
let totalTurns = 0; | |
initialState.forEach((i, index) => { | |
let turns = Math.abs(i - code[index]); | |
if (turns <= 5) { | |
return (totalTurns += turns); | |
} else { | |
const newTurns = 10 - turns; | |
return (totalTurns += newTurns); | |
} |
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
const closestEnemy = (arr) => { | |
let player = []; | |
let enemy = []; | |
let distance = 0; | |
let rowLength = arr[0].length; | |
let board = arr.length; | |
// iterate over the length of the board stored in arrWidth | |
for (let i = 0; i < board; i++) { | |
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
const closestEnemy = (arr) => { | |
let player = []; | |
let enemy = []; | |
let distance = 0; | |
let rowLength = arr[0].length; | |
let board = arr.length; | |
// iterate over the length of the board stored in arrWidth | |
for (let i = 0; i < board; i++) { | |
OlderNewer