Discuss / JavaScript / jiao

格子

#1 Created at ... [Delete] [Delete and Lock User]
'use strict';
function normalize(arr) {

  return  arr.map(name => name.split("").reduce((x, y, index) => {
                if (index == 1) {
                    x = x.toUpperCase();
                }
                y = y.toLowerCase();
                return x + y;
            }));
}

// 测试:
if (normalize(['adam', 'LISA', 'barT']).toString() === ['Adam', 'Lisa', 'Bart'].toString()) {
    console.log('测试通过!');
}
else {
    console.log('测试失败!');
}

  • 1

Reply