Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Still readable solution in Clear category for [old] The Ship Teams by hegemon
"use strict";
function twoTeams(sailors) {
const ships = [[], []];
Object.keys(sailors).sort().forEach(
name => ships[(sailors[name] < 20 || sailors[name] > 40) ? 0 : 1].push(name)
);
return ships;
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(twoTeams({
'Smith': 34,
'Wesson': 22,
'Coleman': 45,
'Abrahams': 19
}))
// These "asserts" are used for self-checking and not for an auto-testing
assert.deepEqual(twoTeams({
'Smith': 34,
'Wesson': 22,
'Coleman': 45,
'Abrahams': 19
}), [
['Abrahams', 'Coleman'],
['Smith', 'Wesson']
])
assert.deepEqual(twoTeams({
'Fernandes': 18,
'Johnson': 22,
'Kale': 41,
'McCortney': 54
}), [
['Fernandes', 'Kale', 'McCortney'],
['Johnson']
])
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Sept. 4, 2018