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 makeCoordinatesZeroBased = rawCoordinates => Object.entries(rawCoordinates) | |
.reduce((processedCoordinates, [coordinate, value]) => { | |
const isCoordinateValid = typeof value === 'number'; | |
let updatedValue = value; | |
if (isCoordinateValid) | |
updatedValue = value - 1; | |
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 makeCoordinatesZeroBased = rawCoordinates => Object.entries(rawCoordinates) | |
.reduce((processedCoordinates, [coordinate, value]) => { | |
const shouldConvert = typeof value === 'number'; | |
const updatedValue = shouldConvert ? value - 1 : value; | |
processedCoordinates[coordinate] = updatedValue; | |
return processedCoordinates; | |
}, {}); |
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 convert = input => Object.entries(input).reduce((acc, [k, v]) => { | |
if (typeof v === 'number') { | |
acc[k] = v - 1 | |
} else { | |
acc[k] = v | |
} | |
return acc | |
}, {}); |
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 fibonacci(number) { | |
var sqRootOf5 = Math.sqrt(5); | |
var Phi = (1+sqRootOf5)/2; | |
var phi = (1-sqRootOf5)/2 | |
return Math.round((Math.pow(Phi, number) - Math.pow(phi, number)) / sqRootOf5); | |
} |
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* fibonacci(number) { | |
var previous_first = 0, previous_second = 1, next = 1; | |
while(true) { | |
next = previous_first + previous_second; | |
previous_first = previous_second; | |
previous_second = next; | |
yield next; |
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 fibonacci(number) { | |
var sequence = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]; | |
var numberZeroBased = number - 1; | |
if (numberZeroBased > sequence.length) | |
throw new Error('The number you provided is outside of the range'); | |
return sequence[numberZeroBased]; | |
}; |
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 fibonacci(number) { | |
var previous_first = 0, previous_second = 1, next = 1; | |
for(var i = 2; i <= number; i++) { | |
next = previous_first + previous_second; | |
previous_first = previous_second; | |
previous_second = next; | |
} | |
return next; |
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
var cache = {}; | |
function fibonacci(number) { | |
if (number < 1) | |
return 0; | |
if (number <= 2) | |
return 1; | |
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 fibonacci(number) { | |
if (number < 1) | |
return 0; | |
if (number <= 2) | |
return 1; | |
return fibonacci(number - 1) + fibonacci(number - 2); | |
} |
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 fibonacci(number) { | |
var sequence = [1, 1]; | |
for (var i = 2; i < number; i++) { | |
sequence[i] = sequence[i-1]+ sequence[i-2]; | |
} | |
return sequence[number-1]; | |
} |
NewerOlder