Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Challenge done #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"liveServer.settings.port": 5501,
"compile-hero.disable-compile-files-on-did-save-code": true
}
11 changes: 11 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diamonts</title>
</head>
<body>
<script src="./src/index.js"></script>
</body>
</html>
1,125 changes: 592 additions & 533 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Hay muchas formas de controlar los argumentos de una función en JS, la idea del reto es que crear una función que reciba una función y la ejecute con los argumentos al revés.",
"main": "index.js",
"dependencies": {
"jest": "^25.4.0"
"jest": "^25.5.4"
},
"devDependencies": {},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/_test_/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { diamond } = require ('../index');
const { diamond } = require('../index').default;

describe('diamond', () => {

Expand Down
47 changes: 42 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
function diamond(size) {
// your code
return;
}
function diamond() {
// your code
let arrayDiamond = []
let size = prompt('Hola, de que tamaño quieres tu diamante?','')
parseInt(size)
if (size <= 1 || size % 2 === 0) return alert("Por favor introduce un número impar")
let diamond = "";

for (let i = 0; i < size; i++) {
let maxSizeDiamond = 2 * i + 1
if (maxSizeDiamond <= size) {
const startPoint = (size - maxSizeDiamond) / 2;
for (let j = 0; j < size; j++) {
if (j >= startPoint && j < (maxSizeDiamond + startPoint)) {
diamond += '*'

} else if (j <= startPoint) {
diamond += ' '
}

}
} else {
const startPoint = (maxSizeDiamond - size) / 2;
const limit = (size * 2) - maxSizeDiamond
for (let j = 0; j < size; j++) {
if (j >= startPoint && j < (limit + startPoint)) {
diamond += '*'
} else if (j <= startPoint) {
diamond += ' '
}

}
}
diamond += '\n'

}
console.log(diamond)
return diamond

}

diamond();

module.exports = { diamond };
37 changes: 37 additions & 0 deletions src/script/index.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use strict";

// function diamond(size) {
// // your code
// if (size < 0 || size % 2 == 0)
// return null;
// let diamond = '';
// for (let index = 0; index < size; index++) {
// const element = 2 * index + 1;
// diamond += ' '.repeat(Math.abs(size - element) / 2) + '*'.repeat(size - Math.abs(size - element)) + '\n';
// }
// return;
// }
module.exports = {
diamond: diamond
};

function diamond(size) {
// your code if (size < 1 || size % 2 !== 1) return null;
return;
var diamondArray = new Array(size);

for (var i = 0; i < diamondArray.length; i++) {
var dimRow = 2 * i + 1;
diamondArray[i] = "".concat(' '.repeat(Math.abs(size - dimRow) / 2)).concat('*'.repeat(size - Math.abs(size - dimRow)));
}

var diamondString = "".concat(diamondArray.join('\n'), "\n");
return diamondString;
}

module.exports = {
diamond: diamond
};
module.exports = {
diamond: diamond
};