Conditional Statement in a map function with es6

半城伤御伤魂 提交于 2019-12-01 14:31:39

I'm not sure why your using the reverse function also, reversing the svg path is slightly more complicated.

This code snippet doubles all the numbers, but leaves M and L intact.

In effect scaling up the svg path by 200%

var array = "M 175 0 L 326.55444566227675 87.50000000000001 L 326.55444566227675 262.5 L 175 350 L 23.445554337723223 262.5 L 23.44555433772325 87.49999999999999 L 175 0".split(" ");

let neWd = array.map(x => {
	if (x === 'M' || x === 'L'){
		return x;
	}else{
		return x * 2;
	}
}).join(' ')

console.log(neWd);
Bergi

Yes, just do it:

let neWd = array.map(x => {
    if (x == "M" || x == "L")
        return x; // unchanged
    else
        return String(parseInt(x, 10) * 2);
}).reverse().join(' ')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!