Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
every revised solution in Clear category for Surjection Strings by Sim0000
import assert from "assert";
function isometricStrings(line1: string, line2: string): boolean {
const d: {[c: string]: string} = {};
return [...line1].every(
(c, i) => (d[c] ??= line2[i]) == line2[i]
);
}
// I wanted to adapt my old code from javascript to more modern typescript.
// my old code
//function isometricStrings(line1: string, line2: string): boolean {
// let d = {};
// return line1.split('').every(
// (c, i) => d[c] == undefined ? (d[c] = line2[i], true) : d[c] == line2[i]
// );
//}
console.log('Example:');
console.log(isometricStrings('add', 'egg'));
// These "asserts" are used for self-checking
assert.equal(isometricStrings('add', 'egg'), true);
assert.equal(isometricStrings('foo', 'bar'), false);
assert.equal(isometricStrings('', ''), true);
assert.equal(isometricStrings('all', 'all'), true);
assert.equal(isometricStrings('gogopy', 'doodle'), false);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
Nov. 21, 2020
Comments: