ZhichengChen 1046e21a90
fix(i18n): update Chinese translation of functional programming (#38061)
* fix(i18n): update Chinese translation of functional programming

* fix(i18n): update review suggestion

Co-authored-by: Zhicheng Chen <chenzhicheng@dayuwuxian.com>
2020-08-05 14:08:04 +05:30

2.1 KiB
Raw Blame History

id, title, challengeType, forumTopicId, localeTitle
id title challengeType forumTopicId localeTitle
587d7da9367417b2b2512b66 Combine Two Arrays Using the concat Method 1 301229 使用 concat 方法组合两个数组

Description

Concatenation意思是将元素连接到尾部。同理JavaScript 为字符串和数组提供了concat方法。对数组来说,在一个数组上调用concat方法,然后提供另一个数组作为参数添加到第一个数组末尾,返回一个新数组,不会改变任何一个原始数组。举个例子:
[1, 2, 3].concat([4, 5, 6]);
// 返回新数组 [1, 2, 3, 4, 5, 6]

Instructions

nonMutatingConcat函数里使用concat,将attach拼接到original尾部,返回拼接后的数组。

Tests

tests:
  - text: 应该使用<code>concat</code>方法。
    testString: assert(code.match(/\.concat/g));
  - text: 不能改变<code>first</code>数组。
    testString: assert(JSON.stringify(first) === JSON.stringify([1, 2, 3]));
  - text: 不能改变<code>second</code>数组。
    testString: assert(JSON.stringify(second) === JSON.stringify([4, 5]));
  - text: <code>nonMutatingConcat([1, 2, 3], [4, 5])</code>应返回<code>[1, 2, 3, 4, 5]</code>。
    testString: assert(JSON.stringify(nonMutatingConcat([1, 2, 3], [4, 5])) === JSON.stringify([1, 2, 3, 4, 5]));

Challenge Seed

function nonMutatingConcat(original, attach) {
  // Add your code below this line


  // Add your code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
nonMutatingConcat(first, second);

Solution

function nonMutatingConcat(original, attach) {
  // Add your code below this line
  return original.concat(attach);
  // Add your code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
nonMutatingConcat(first, second);