Convert seconds to compound duration: Difference between revisions
Content added Content deleted
(→ES6) |
(→ES6: Slight simplification) |
||
Line 1,279: | Line 1,279: | ||
<lang JavaScript>(() => { |
<lang JavaScript>(() => { |
||
// angloDuration :: Int -> String |
// angloDuration :: Int -> String |
||
function angloDuration(intSeconds) { |
function angloDuration(intSeconds) { |
||
return |
return weekParts(intSeconds) |
||
⚫ | |||
.reduce((a, x) => |
.reduce((a, x) => |
||
a.concat(x[0] ? [`${x[0]} ${x[1]}`] : []), [] |
a.concat(x[0] ? [`${x[0]} ${x[1]}`] : []), [] |
||
Line 1,288: | Line 1,289: | ||
.join(', '); |
.join(', '); |
||
} |
} |
||
// weekParts :: Int -> [Int] |
// weekParts :: Int -> [Int] |
||
let weekParts = intSeconds => [undefined, 7, 24, 60, 60] |
let weekParts = intSeconds => [undefined, 7, 24, 60, 60] |
||
Line 1,295: | Line 1,296: | ||
let r = a.rem, |
let r = a.rem, |
||
mod = isNaN(x) ? r : r % x; |
mod = isNaN(x) ? r : r % x; |
||
return { |
return { |
||
rem: (r - mod) / (x || 1), |
rem: (r - mod) / (x || 1), |
||
Line 1,305: | Line 1,306: | ||
}) |
}) |
||
.parts, |
.parts, |
||
// zipWithEnglish :: [Int] -> [(Int, String)] |
// zipWithEnglish :: [Int] -> [(Int, String)] |
||
zipWithEnglish = |
zipWithEnglish = xs => xs |
||
.map((v, i) => [v, ["wk", "d", "hr", "min","sec"][i]]); |
|||
return lstValues.length === keys.length ? ( |
|||
⚫ | |||
) : undefined; |
|||
} |
|||
// TEST |
// TEST |
||
return [7259, 86400, 6E6] |
return [7259, 86400, 6E6] |
||
Line 1,322: | Line 1,320: | ||
) |
) |
||
.join("\n"); |
.join("\n"); |
||
})();</lang> |
})();</lang> |
||