0

Нужно создать массив arr = ['a', 'b', 'c', 'd'] и с его помощью вывести на экран строку 'a+b, c+d'.

1
  • 1
    и ваше решение где?
    – teran
    26 мар 2020 в 9:31

3 ответа 3

2

arr = ['a', 'b', 'c', 'd']

b = [...arr.join((+(+!+[]+(!+[]+[])[!+[]+!+[]+!+[]]+[+!+[]]+[+[]]+[+[]])+[])[2])]
b.splice(!![]+!![]+!![],!![],["",""]," ")
console.log(b.join``)

1
1

const arrayChunk = (arr, size) =>
  Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
    arr.slice(i * size, i * size + size)
  );


console.log(arrayChunk(['a', 'b', 'c', 'd'], 2).map(a => a.join`+`).join`,`);
console.log(arrayChunk(['a', 'b', 'c', 'd', 'e'], 2).map(a => a.join`+`).join`,`);
console.log(arrayChunk(['a', 'b', 'c', 'd', 'e', 'f'], 2).map(a => a.join`+`).join`,`);
// По три
console.log(arrayChunk(['a', 'b', 'c', 'd', 'e', 'f'], 3).map(a => a.join`+`).join`,`);
// По четыре
console.log(arrayChunk(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], 4).map(a => a.join`+`).join`,`);

0

Возможно, вам такая реализация будет более понятна

arr = ['a', 'b', 'c', 'd']

class magicCalculate {
  constructor(magic) {
      this.a = magic.a,
        this.b = magic.b,
        this.c = magic.c,
        this.d = magic.d
    }
    ['return' + 'AB']() {
      return [this.a, this.b]
    }
    ['return' + 'CD']() {
      return [this.c, this.d]
    }
  refundplus(value) {
    return new String(value.join('+'))
  }
  get returnConsLog() {
    return console.log
  }
}

class magicVal extends magicCalculate {
  ['console' + 'Log'](value) {
    super.returnConsLog(value)
  }
  ['add' + 'Slash'](value) {
    return '\'' + value + '\'';
  }
}

const [a, b, c, d] = arr
magic = new magicVal({a: a, b: b, c: c, d: d})
str1 = magic.refundplus(magic.returnAB())
str = [str1, magic.refundplus(magic.returnCD())]
magic.consoleLog(magic.addSlash(str.join(', ')))

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.