When we are equal, we are identical
Codewars python kata 7kyu js translation version one
by trentHarlem
HTML
https://www.codewars.com/kata/60c47b07f24d000019f722a2/discuss
JavaScript
// Work in Progress
function makeIdentical(string) {
// operands get placed in array
// operands get trimmed
// operands get sorted by length
let [a, b] = string.split('===').map(s => s.trim()).sort((x, y) => x.length - y.length)
console.log(a, b)
// operands get compared
if (a === b) {
return true
}
// check primitive type
if (typeof(a) !== typeof(b)) {
return false
} else {
// operands get modified if necessary
while (b !== a) {
b = b.slice(0, -1)
console.log('a', a, 'b', b)
if (a === b) {
break;
}
}
}
// modified operands get compared
return a === b
}
//
let truthy = `abc===abc`
let falsy = `abc===abcd`
let test_Spaces = `abc === abcd` // requires some type of trim()
let test_No_Spaces = `abcde===abc` // operands get sorted by length
//console.log(makeIdentical(test))
console.log('testTrue', makeIdentical(truthy))
console.log('testFalse', makeIdentical(falsy))
console.log('spaces', makeIdentical(test_Spaces))
console.log('NO spaces', makeIdentical(test_No_Spaces))
// # // javascript === test for strict equality
// # // javascript typeof('test') test for identify
// # // javascript
//const myString = 'test'
//typeof('test') === 'string' = true
//console.log(typeof(myString) === 'string') // # // = true
//import codewars_test as test
//from solution import make_identical
//@test.describe("Basic tests")
//def _():
// @test.it("Example Test")
// def _():
// test.assert_equals("abc" is make_identical("abcd"[:-1]), True)