pocesar8 years ago
JS replace quirk
Strings
Data Types
Arrays
Not really useful, but calling replace with an array as replacement calls toString on it. It doesn't work the same using objects
const weird = 'asdf'.replace('a', [])
const weirdness = 'asdf'.replace('a', [1,2])
const volatile = 'asdf'.replace('a', {})
// TODO: Replace examples and use TDD development by writing your own tests
// These are some CW specific test methods available:
// Test.expect(boolean, [optional] message)
// Test.assertEquals(actual, expected, [optional] message)
// Test.assertSimilar(actual, expected, [optional] message)
// Test.assertNotEquals(actual, expected, [optional] message)
// NodeJS assert is also automatically required for you.
// assert(true)
// assert.strictEqual({a: 1}, {a: 1})
// assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
// You can also use Chai (http://chaijs.com/) by requiring it yourself
// var expect = require("chai").expect;
// var assert = require("chai").assert;
// require("chai").should();
describe("Solution", function(){
it("should test for something", function(){
Test.assertEquals(weird, 'sdf');
Test.assertEquals(weirdness, '1,2sdf');
Test.assertEquals(volatile, '[object Object]sdf');
});
});