'Trying to solve an Exercism question, Gigasecond, Javacsript
I am trying to solve a problem: Given a moment, determine the moment that would be after a gigasecond has passed. A gigasecond is 10^9 (1,000,000,000) seconds.Do not mutate the function's arguments.
const gigasecond = () => {
\\write your code here
};
I wrote a code which I think should solve it, but, I am getting a failed test. My code is:
const gigasecond = () => {
let date = new Date();
const gs = Math.pow(10, 12);
let futureTime = date.getTime() + gs;
return new Date(futureTime)
};
I am really stuck, and not sure what did I miss.
Solution 1:[1]
If I add an argument my code will be:
const gigasecond = (time) => {
let date = time.getTime();
const gs = Math.pow(10, 12);
let futureTime = date + gs;
return new Date(futureTime)
};
and it did pass the first test. I'll cross fingers and see if it is accepted or not.
Solution 2:[2]
My solution is as follow:
public static class Gigasecond {
public static DateTime Add(DateTime moment)
{
return moment.AddSeconds(Math.Pow(10,9));
}
}
Solution 3:[3]
My Solution is as follows:
import datetime
def add(moment):
return moment+ datetime.timedelta(seconds=10**9)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sumalille |
| Solution 2 | Noor Mustafa |
| Solution 3 | Darsh Patel |
