문제
Map, Filter, Reduce - Code Exercises | CroCoder
Map, filter and reduce are the most useful array methods to manipulate arrays and often the hardest to master. Try to solve the given exercises!
www.crocoder.dev
정답
const input = "Every developer likes to mix kubernetes and javascript";
const answer = input.split(" ").map(x => (x.length > 3 ? (x = x.split("")[0] + (Number(x.length) - 2) + x.split("")[x.length - 1]) : x));
console.log(answer);
const input = "Every developer likes to mix kubernetes and javascript";
const arr = input.split(" ");
for (let i = 0; i < arr.length; i++) {
if (arr[i].length > 3) {
arr[i] = arr[i].split("")[0] + (Number(arr[i].length) - 2) + arr[i].split("")[arr[i].length - 1];
}
}
console.log(arr);