Are the two js statements always returning the same result? s.replace(/\t/g, '|') vs s.split('\t').join('|')

AGamePlayer

First:

var s = input_string.replace(/\t/g, '|');

Second:

var s = input_string.split('\t').join('|');

Is there any possibility that they could get different results?

CertainPerformance

Assuming that input_string is a plain string, and that none of the build-in methods String.prototype.replace, String.prototype.split, Array.prototype.join have been tampered with - then no, .replace followed by .join in that matter will always produce the same output.

If you allow for the possibility that the methods have been patched, then all bets are off.

String.prototype.replace = () => '';
console.log('foo'.replace(/\t/g, '|'));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why aren't these two sql statements returning same output?

Keras Sequential prediction always returning the same result

For JS strings, is s === "" always the same as s.length == 0?

Mysql - delete with join vs two delete statements

Join two sql statements in same table

Collapse result of join's two columns into one column

Fix for select returning no result(s)

Python's sum not returning same result as NumPy's numpy.sum

Is there in lodash comparing two arrays of objects that will not be shown if there's same result

Random (?) number generation in R using sample() always returning the same result

Groovy Regex: String Split pattern not returning same result as Matcher pattern

Resteasy application always returning 404s

T-SQL split result into two rows

Perform JOIN in SQLITE on two SELECT statements from the same table

are these two XML`s the same?

Powershell split() vs -split - what's the difference?

AND Statements in JOIN vs WHERE

Java Regex Split \\S --> Strange result for String split methode \\S

Ajax POST request to Shopify's /cart/add.js always returning on error callback function

Join two Python dictionaries based on same value but different key name (like SQL's JOIN)

Can't get facebook login to work on MVC5. It's always returning NULL on GetExternalLoginInfoAsync()

mysql: join two tables, and after split a column of the result table

Two IF statements and join MYSQL

Two machines returning a different encoding result for the same file

What's the difference between these two statements in Javascript?

What's the semantical difference between the two statements?

what's the difference between the two statements?

Why won't calling a nested function result in returning original function's value?

Ember.js two API's same resource name