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 Rounin
"use strict";
function twoTeams(sailors) {
return [
Object.keys(sailors).filter(function(x) { return sailors[x] > 40 || sailors[x] < 20; }).sort(),
Object.keys(sailors).filter(function(x) { return sailors[x] <= 40 && sailors[x] >= 20; }).sort()
];
}
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!");
}
March 13, 2019