export function solution(arraySecreto) {
return(typeof arraySecreto[0] === "string"? true: false)
}
Introducción a JavaScript
¿Por qué JavaScript?
¿Qué es JavaScript y para qué sirve?
Elementos de un Lenguaje de Programación: Variables, Funciones y Sintaxis
Qué es una variable en JavaScript
Qué son las funciones en JavaScript
¿Qué es una función declarativa y una expresiva?
Playground: retorna el tipo
Quiz: Introducción a JavaScript
Bases de JavaScript
Scope
Hoisting
Coerción
Valores: Truthy y Falsy
Operadores: Asignación, Comparación y Aritméticos.
Playground: compara un número secreto
Quiz: Bases de JavaScript
Condicionales
Condicionales: If, Else, else if
Switch
Playground: tienda de tecnología
Quiz: Condicionales
Arrays
¿Qué es un array?
Playground: detecta el elemento impostor de un array
Quiz: Arrays
Loops
Loops: For y For...of
Loops: While
Playground: rescata al estudiante
Objects
Objects
Objects: Función constructora
Playground: permiso para conducir
Métodos de Arrays
Métodos de recorridos de Arrays
Recorriendo Arrays con .find(), .forEach() y .some()
Eliminando elementos de un Array
Playground: Arregla el Bug
Quiz: Métodos de Arrays
Próximos pasos con JavaScript
Continúa con el Curso Práctico de JavaScript
No tienes acceso a esta clase
¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera
Aportes 200
Preguntas 14
export function solution(arraySecreto) {
return(typeof arraySecreto[0] === "string"? true: false)
}
Mi solución con lo visto hasta ahora:
Dejo 2 soluciones :
Dejo ambas soluciones:
export function solution(arraySecreto) {
return(typeof arraySecreto[0] == "string"? true : false)
}
export function solution(arraySecreto) {
if (typeof arraySecreto[0] == "string") {
return true;
} else {
return false;
}
}
export function solution(arraySecreto) {
if (typeof arraySecreto[0] == “string”) {
return true;
} else {
return false;
}
}
export function solution(arraySecreto) {
if (typeof arraySecreto[0] === "string") {
return true;
} else {
return false;
}
}
export function solution(arraySecreto) {
return typeof arraySecreto[0] === "string"
}
Una forma corta de hacerlo con poco código; es una sola línea:
export function solution(arraySecreto) {
return typeof arraySecreto[0] === ‘string’
}
export function solution (arraySecreto) {
if (typeof arraySecreto[0] === ‘string’)
{ return true }
else {
return false;
}
}
Mi solicion larguita pero entendible
<export function solution(arraySecreto) {
let primero = arraySecreto.shift()
console.log(primero)
let tipo = typeof primero
console.log(tipo)
if (tipo === "string") {
return (true)
}
else {
return (false)
}
}
solution(["huevo", "gallina", "vaca"])
solution([1, "gallina", "vaca"])
>
function solution(arraySecreto){
if(typeof arraySecreto[0] == 'string'){
return true;
} else {
return false;
}
}
export function solution(arraySecreto) {
return (typeof arraySecreto[0] === “string” ?? false);
}
export function solution(arraySecret) {
const firstElementArray = arraySecret[0];
return typeof firstElementArray === 'string';
}
return typeof arraySecreto[0] === 'string' ? true : false;
export function solution(arraySecreto) {
// Tu código aquí 👈
var respuesta;
if (typeof arraySecreto[0] == “string”) {
respuesta = true;
}
else {
respuesta = false;
}
return respuesta;
}
Mi solución
export function solution(arraySecreto) {
return typeof arraySecreto[0] === “string” ? true : false;
}
A primeras lo hice con un if:
if (typeof arraySecreto[0] === 'string') {
return true
} else {
return false
}
Luego recordé la clase de los operadores. Ya el operador de comparación “===” va a regresar un booleano y lo acorté.
export function solution(arraySecreto) {
return typeof arraySecreto[0] === 'string';
}
export function solution(arraySecreto) {
// Tu código aquí 👈
return typeof arraySecreto[0] === "string" ? true : false;
}
Reto Array
export function solution(arraySecreto) {
if (typeof arraySecreto[0] === "string") {
return (true);
} else{
return (false);
}
}
solution(["Huevo", "Gallina", "Vaca"])
solution([1, "Gallina", "Vaca"])
export function solution(arraySecreto) {
if (typeof arraySecreto[0] === "string") {
return true;
} else {
return false;
}
}
Asi lo hice yo!! espero les sirva ♥
export function solution(arraySecreto) {
if (typeof arraySecreto[0] === "string") {
return true;
} else {
return false;
}
}
export function solution(arraySecreto) {
// Tu código aquí 👈
return typeof arraySecreto[0] === "string" ? true : false;
}
Hola, pude completar el reto así:
export function solution(arraySecreto) {
// Tu código aquí 👈
return Boolean(typeof(arraySecreto.shift()) === typeof("Huevo"))
}
Mi aporte
return (typeof (arraySecreto[0]) === typeof (" "));
MI solución.
export function solution(arraySecreto) {
return typeof arraySecreto[0] === 'string' ? true : false;
}
mi solución
export function solution(arraySecreto) {
if (typeof arraySecreto[0] == "string") {
return true;
} else {
return false;
}
}
function solution(arraySecreto) {
console.log(typeof arraySecreto[0] === "string"? true:false)
}
solution(["Huevo", "Gallina", "Vaca"])
solution([1, "Gallina", "Vaca"])
function solution(arraySecreto) {
return Boolean(typeof arraySecreto[0] === "string")
}
export function solution(arraySecreto) {
if (typeof arraySecreto[0] == “string”) {
return true;
} else {
return false;
}
}
export function solution(arraySecreto) {
if (typeof (arraySecreto.shift()) == 'string') {
return true;
}
return false;
}
export function solution(arraySecreto) {
return typeof (arraySecreto [0]) === "string" ? true : false
}
asi mi aporte, sencillo
function solution(arraySecreto) {
if (typeof arraySecreto[0] === "string") {
return true;
}else {
return false;
}
}
solution(["Huevo", "Gallina", "Vaca"])
solution([1, "Gallina", "Vaca"])
Aplicando lo aprendido hasta ahora…operador ternario
function solution(arraySecreto) {
let primerValor = arraySecreto[0];
if (typeof primerValor == "string") {
return true;
} else {
return false;
}
}
Hola, quiero mostrarles mi solucion
export function solution(arraySecreto) {
if (typeof arraySecreto[0] === "string") {
return true;
} else {
return false;
}
}
export function solution(arraySecreto) {
// Tu código aquí 👈
return Boolean(typeof(arraySecreto[0]) === “string”)
}
Dejo mi solucion:
export function solution(arraySecreto) {
let result;
if (typeof arraySecreto[0] === "string") {
result = true;
}
else if (typeof arraySecreto[0] === "number") {
result = false;
}
return (result);
}
export function solution(arraySecreto){
if (typeof arraySecreto[0] == ‘string’) {
return true;
} else {
return false;
}
}
solution([1,“Gallina”,“Vaca”])
solution([“Huevo”,“Gallina”,“Vaca”])
export function solution(arraySecreto) {
return typeof (arraySecreto[0]) === "string"
}
export function solution(arraySecreto) {
// Tu código aquí 👈
if (typeof arraySecreto[0] == "string") {
return true
} else {
return false
}
}
Imagen anti-spoiler.
Este gatito sabe que tu puedes, solo debes intentarlo. Miralo, está confiando en ti.
export function solution(arraySecreto) {
if (typeof arraySecreto[0] === "string") {
return true
} else {
return false
}
}
export function solution(arraySecreto) {
if (typeof arraySecreto[0] === “string”){
return true;
} else {
return false;
}
}
Es mi solución eficiente?
Mi solución utilizando condicional:
export function solution(arraySecreto) {
if (typeof arraySecreto[0] === "string") {
return true
}
else {
return false
}
}
export function solution(arraySecreto) {
// Tu código aquí 👈
return typeof arraySecreto[0] === “string” ? true : false;
}
Una solución
export function solution(arraySecreto) {
switch (typeof arraySecreto[0]) {
case "string": return true
break;
default: return false;
}
}
Es increíble como puede haber mas de 1 manera de logra el resultado según la lógica que apliquemos
Les comparto tres formas de resolver el reto:
Lo hice asi , pero creo que no es lo optimo:
export function solution(arraySecreto) {
if (arraySecreto[0] === String(arraySecreto[0])){
return true;
}
else {
return false;
}
}
Les dejo una soluciòn donde utilizo el metodo “shift” para separar el elemento del arreglo :3
export function solution(arraySecreto) {
var firstElement = arraySecreto.shift();
return (typeof firstElement == 'string' ? true : false)
}
export function solution(arraySecreto) {
return (typeof arraySecreto[0])==“string”
}
export function solution(arraySecreto) {
if (typeof (arraySecreto[0]) !== "string") {
return false;
} else {
return true;
}
}
<code>
export function solution(arraySecreto) {
// Tu código aquí 👈
let numero = true;
arraySecreto.forEach(index => {
if (typeof (index) != 'string') { numero = false }
});
return numero;
}
export function solution(arraySecreto) {
// Tu código aquí 👈
if (typeof arraySecreto[0] === “string”) return true;
return false;
}
Solo tuve problemas con las comillas del STRING
return typeof arraySecreto[0] === "string";
Ejercicio:
La solucion mas corta que pude encontrar
export function solution(arraySecreto) {
return typeof arraySecreto[0] == "string";
}
Me encanta tratar de encontrar maneras de escribir menos codigo donde sea posible, asi que si alguien sabe de una solucion mas corta, me dicen 😄
export function solution(arraySecreto) {
var posicion = arraySecreto.indexOf(1);
if (posicion === -1) {
return true
} else {
return false
}
}
solution(["Huevo", "Gallina", "Vaca"])
solution([1, "Gallina", "Vaca"])
Hola comunidad este es mi aporte al desafio
export function solution(arraySecreto) {
// Tu código aquí 👈
var result;
result = typeof arraySecreto[0] == "string" ? true : false;
return result;
}
mi aporte:
export function solution(arraySecreto) {
// Tu código aquí 👈
return typeof(arraySecreto[0]) == 'string'
}
ya vi varios que lo hacen en una sola línea pero fue lo primero que vi cuando entré y me negué rotundamente a hacerlo igual.
switch (typeof arraySecreto[0]) {
case "string":
return true;
break
default:
return false;
}
export function solution(arraySecreto) {
// Tu código aquí 👈
return typeof arraySecreto[0] === “string” ? true : false;
}
reto.
export function solution(arraySecreto) {
// Tu código aquí 👈
if (typeof (arraySecreto[0])=== "string") {
return (true)
}
else {return (false)}
}
Lo logré! Estoy empezando pero este fue especialmente satisfactorio jejejej
Buenas tardes, comparto mi propuesta de solución a este desafío:
export function solution(arraySecreto) {
// Tu código aquí 👈
var res = typeof (arraySecreto[0]);
if (res == "string") {
return true;
} else {
return false;
}
}
ok, sigo en este proceso de entednerlo, aunque siendo sincero, tuve que mirar las respuestas de mis compañeros para lograr entenderlo mejor.
Aqui les dejo mi forma de solucionar este reto 😃
export function solution(arraySecreto) {
var tipo = typeof (arraySecreto[0]);
return tipo === "string";
}
export function solution(arraySecreto) {
// Tu código aquí 👈
return typeof (arraySecreto.shift()) === "string"
}
solution(["Huevo", "Gallina", "Vaca"])
solution([1, "Gallina", "Vaca"])
mi solucion:
Mi solucion al reto con Switch:
export function solution(arraySecreto) {
switch (true) {
case (typeof (arraySecreto[0]) === "string"):
return true
break;
default:
return false
}
}
<export function solution(arraySecreto) {
// Tu código aquí 👈
if ( arraySecreto[0] === "Huevo") {
return ( true)
} else {
return(false)
}
}>
MI SOLUCION
export function solution(arraySecreto) {
// Tu código aquí 👈
return typeof (arraySecreto[0]) === "string"
}
solution(["Huevo", "Gallina", "Vaca"])
solution([1, "Gallina", "Vaca"])
Comparto mi aporte, en mas lineas de codigo que las propuestas pero utilizando la comparacion ternaria
export function solution(arraySecreto) {
var comparacion = typeof(arraySecreto[0]);
var resultado = comparacion === "string" ? true : false;
return(resultado);
}
export function solution(arraySecreto) {
var primer = arraySecreto[0];
var tipo = typeof primer;
if (tipo === “string”) {
return true;
}
else {
return false;
}
}
ahora sé que lo pude hacer mas corto pero fue lo primero que se me ocurrió.
export function solution(arraySecreto) {
return typeof arraySecreto[0] === 'string';
}
solution(["Huevo", "Gallina", "Vaca"])
solution([1, "Gallina", "Vaca"])
function solution(arraySecreto) {
if (typeof arraySecreto[0] === 'string') {
return true
} else {
return false
}
}
export function solution(arraySecreto) {
// Tu código aquí 👈
return typeof (arraySecreto[0]) == “string”
}
Lo imaginé de esta manera:
<var aTipo = typeof arraySecreto[0];
if (aTipo === 'string') {
return true
} else {
return false
}>
export function solution(arraySecreto) {
return typeof (arraySecreto[0]) === "string";
}
Yo lo puse así en la consola y me funcionó
(a veces me da error cuando se me olvida quitar el export del principio del ejercicio para ponerlo en la consola)
function solution(arraySecreto) {
if (typeof arraySecreto[0] === "string") {
return true;
} else {
return false
}
}
solution(["Huevo", "Gallina", "Vaca"])
solution([1, "Gallina", "Vaca"])
export function solution(arraySecreto) {
// Tu código aquí 👈
return (typeof arraySecreto[0] === “string”);
}
export function solution(arraySecreto) {
if (typeof (arraySecreto[0]) == “string”) {
return (true)
}
else {
return (false)
}// Tu código aquí 👈
}
Hay 2 posibles soluciones, ambas usando if, pero una de ellas con el metodo ternario.
let cosas = ["Huevo", "Gallina", "Vaca"];
console.log (cosas[0]);
console.log(typeof(cosas[0]));
if (typeof(cosas[0]) == "string"){
console.log("yes");
}
export function solution(arraySecreto) {
return (typeof arraySecreto[0] == “string”)
}
Realice la validación usando la Igualdad Estricta que da como resultado Boolean true or false
.
typeof arraySecreto[0] === 'string'
export function solution(arraySecreto) {
if (typeof arraySecreto[0] === “string”) {
return true;
}
else {
return false;
}
}
este es mi approach
export function solution(arraySecreto) {
return typeof arraySecreto[0] === 'string'
}
export function solution(arraySecreto) {
// Tu código aquí 👈
return typeof (arraySecreto.shift()) === “string” ? true : false;
}
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?
o inicia sesión.