This commit is contained in:
Philippe Torrel
2026-07-07 10:29:34 +02:00
parent f3ca79e09b
commit f583bf92a3
14 changed files with 201 additions and 61 deletions

View File

@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
@@ -27,7 +27,9 @@
<script>
'use strict';
const image = [
'use strict';
const imageAr = [
[
// Row 1
[100, 150, 200], // Pixel 1
@@ -40,12 +42,44 @@
],
];
const increaseBrightness = (image, value) => {
const increaseBrightness = (imageAr = [], value) => {
// Your code here
return imageAr.map((row) => {
return row.map((rgbValue) => {
return rgbValue.map((elem) => {
const result = elem + value;
if (result > 255) {
return 255;
}
return result;
});
});
});
};
const newImage = increaseBrightness(image, 30);
const increaseBrightness2 = (image, value) => {
const imageAr = image.map((row) => {
const rows = row.map((pixel) => {
const pixels = pixel.map((color) => {
return Math.min(255, color + value);
});
return pixels;
});
return rows;
});
return imageAr;
};
console.time('guard');
const newImage = increaseBrightness(imageAr, 30);
console.log(newImage);
console.timeEnd('guard');
console.time('Math');
const newImage2 = increaseBrightness2(imageAr, 30);
console.log(newImage2);
console.timeEnd('Math');
/*
Expected outcome:
[