Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Follow Instructions by vvm70
import assert from "assert";
function follow(instructions: string) {
let dir = [];
let word = instructions.split('');
dir[0] = word.filter(a => a == 'r').length - word.filter(a => a == 'l').length;
dir[1] = word.filter(a => a == 'f').length - word.filter(a => a == 'b').length;
return dir;
}
console.log('Example:');
console.log(follow('fflff'));
// These "asserts" are used for self-checking
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!");
July 6, 2020