Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
split, filter, length solution in Clear category for [old] Follow Instructions by Sim0000
"use strict";
function follow(instructions) {
const f = c => instructions.split('').filter(x => x == c).length; // count c in instructions
return [f('r') - f('l'), f('f') - f('b')];
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(follow("fflff"))
// These "asserts" are used for self-checking and not for an auto-testing
assert.deepEqual(follow("fflff"), [-1, 4])
assert.deepEqual(follow("ffrff"), [1, 4])
assert.deepEqual(follow("fblr"), [0, 0])
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
April 18, 2019
Comments: