diff --git a/src/arrayMethodJoin.js b/src/arrayMethodJoin.js index 3a62201c..81f93c85 100644 --- a/src/arrayMethodJoin.js +++ b/src/arrayMethodJoin.js @@ -1,11 +1,62 @@ 'use strict'; -/** - * Implement method join - */ function applyCustomJoin() { + /** + * @param {string | undefined} separator + * @returns {string} */ [].__proto__.join2 = function(separator) { - // write code here + let inerSeparator; + let joined = ''; + let temp = ''; + + if (this.length === 0) { + return joined; + } + + switch (separator) { + case null: + inerSeparator = 'null'; + break; + + case undefined: + inerSeparator = ','; + break; + + default: + inerSeparator = separator; + } + + for (let i = 0, last = this.length - 1; ; i++) { + temp = this[i]; + + switch (temp) { + case null: + case undefined: + temp = ''; + break; + case true: + temp = 'true'; + break; + case false: + temp = 'false'; + break; + case NaN: + temp = 'NaN'; + break; + default: + break; + } + + joined += temp; + + if (i === last) { + break; + } + + joined += inerSeparator; + } + + return joined; }; }