Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] The Ship Teams by EvgNikitin
"use strict";
function twoTeams(sailors) {
var small = [],
big = [];
for (let key in sailors) {
if (sailors[key] >= 20 && sailors[key] <= 40) {
big.push(key);
} else {
small.push(key);
}
}
big.sort();
small.sort();
return [
small,
big
];
}
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. 13, 2018