假设我首先有一个具有r、g、b值属性的对象列表像这样的东西:
let color_pixels = [{r: 100, g: 20, b: 40}, {r: 80, g: 50, b: 30}];
let image = function(color_pixels) {
}
如何将每个属性相乘,并用函数中相乘的属性更新数组?
const colorPixels = [{r: 100, g: 20, b: 40}, {r: 80, g: 50, b: 30}];
const image = multiply(colorPixels, 1.5)
function multiply(pixels, factor) {
return pixels.map(pixel => {r: pixel.r * factor, g: pixel.g * factor, b: pixel.b * factor})
}
或者根据需要修改映射回调返回值。