小编Mah*_*Ali的帖子

How do I check if a string is entirely made of the same substring?

I have to create a function which takes a string, and it should return true or false based on whether the input consists of a repeated character sequence. The length of the given string is always greater than 1 and the character sequence must have at least one repetition.

"aa" // true(entirely contains two strings "a")
"aaa" //true(entirely contains three string "a")
"abcabcabc" //true(entirely containas three strings "abc")

"aba" //false(At least there should be two same substrings and nothing more) …
Run Code Online (Sandbox Code Playgroud)

javascript string algorithm

125
推荐指数
9
解决办法
1万
查看次数

如何使用css网格制作垄断板?

我想创建一个像 在此处输入图片说明. 板子有以下特点

  • 角是方形的,比其他盒子大
  • 每行的文本都面向特定的角度。

我的基本 html 结构如下

  • 木板
    • 第 1 行
      • 瓷砖 1
      • 瓷砖 2 ...

我成功地使用grid-template-areas. 我面临的问题是我无法根据需要旋转每一行的瓷砖。

我创建了一个基本片段,每行只有 3 个图块。第一排朝向直角,所有其他排都朝向错误的角度。90deg对于第二行。180deg对于第三行。和270deg第四行。

我试过使用writing-modeandtransform:rotate()但它不起作用或者我使用它的方式错误。请帮我找到正确的方法。我会很感激

*{
  box-sizing: border-box;
}
#board {
   display: grid;
   /*first and last row and column are bigger than others*/
   grid-template-columns: 100px repeat(2, 70px) 100px;
   grid-template-rows: 100px repeat(2, 70px) 100px;
   
   /*a, b, c, d are 4 rows and o is center*/
   grid-template-areas:
      "c c c d"
      "b …
Run Code Online (Sandbox Code Playgroud)

html css css-grid

40
推荐指数
3
解决办法
3470
查看次数

未捕获的类型错误:无法解构“未定义”或“空”的属性“名称”

在传递空对象的情况下,对象解构会引发错误

function test ({name= 'empty'}={}) {
  console.log(name)
}
test(null);
Run Code Online (Sandbox Code Playgroud)

未捕获的类型错误:无法解构name“未定义”或“空”的属性。在测试 (:1:15) 在 :1:1

javascript ecmascript-6 object-destructuring

17
推荐指数
1
解决办法
8万
查看次数

如何在打字稿中获取异步函数的返回类型?

考虑我们有一个如下所示的函数

const upper = (str: string) : string => string.toUpperCase() 
Run Code Online (Sandbox Code Playgroud)

我们可以使用以下方法获取函数的类型ReturnType

type Test = ReturnType<typeof upper>
Run Code Online (Sandbox Code Playgroud)

但现在考虑我们有一个异步函数。

const getUserData = async (uid: string): Promise<{name: string, email: string}> => {
   ...
};
Run Code Online (Sandbox Code Playgroud)

现在我们怎样才能得到这种类型{name: string, email: string}

javascript typescript

16
推荐指数
2
解决办法
7626
查看次数

How to get diagonal numbers between two number in a matrix?

How to check if two indexes of a square matrix are diagonal to each other. Consider the array.

[
 0 , 1 , 2 , 3 ,
 4 , 5 , 6 , 7 ,
 8 , 9 , 10, 11,
 12, 13, 14, 15
]
Run Code Online (Sandbox Code Playgroud)

Create a function which takes three parameters array and two indexes. It should return a true if two indexes are diagonal to each other otherwise return false For above array.

0,15 => true
3,12 …
Run Code Online (Sandbox Code Playgroud)

javascript arrays algorithm

12
推荐指数
2
解决办法
684
查看次数

有没有办法自定义自动完成弹出菜单 vscode?

请投票支持功能请求https://github.com/microsoft/vscode/issues/113463

我正在创建一个扩展程序,我需要自定义建议菜单。我想在建议的末尾添加数字。 在此处输入图片说明

我不是要求完整的解决方案。我只是要求启动只是为了编辑自动完成菜单并在其末尾添加一些自定义文本。我搜索了很多,但没有找到编辑自动完成菜单的方法。

编辑:搜索这个我发现它可能链接vscode.CompletionItemProvider

编辑:它不想要特别在行尾的数字。它们可能位于完整项目的开头。

注意:我已经在 github 上打开了一个问题https://github.com/microsoft/vscode/issues/113463

javascript visual-studio-code vscode-extensions

9
推荐指数
0
解决办法
319
查看次数

声明的变量和定义的变量之间是否有区别

我尝试在控制台中一一写入以下行

let x = y //throws error "Uncaught ReferenceError: y is not defined"
console.log(x) //throws error "ReferenceError: x is not defined"
let x = 3; //gives error "Uncaught SyntaxError: Identifier 'x' has already been declared"
x = 3 //ReferenceError: x is not defined
Run Code Online (Sandbox Code Playgroud)

现在的问题是,如何不能定义变量并同时对其进行声明。两者之间有什么区别。

javascript variables

6
推荐指数
1
解决办法
155
查看次数

按升序排序天数数组

我有一个包含日期名称的唯一字符串的数组。日期名称将以随机顺序排列。-例如:

["Sun 10am", "Sat 4pm", "Sat 10am", "Wed 3pm", "Sun 4pm"]
Run Code Online (Sandbox Code Playgroud)

我想使用javascript对该数组进行排序,以便它以升序排列。

["Wed 3pm", "Sat 10am", "Sat 4pm", "Sun 10am", "Sun 4pm"]
Run Code Online (Sandbox Code Playgroud)

有人可以建议最好的方法吗?

谢谢

javascript sorting algorithm node.js

6
推荐指数
2
解决办法
137
查看次数

如何在具体情况下停止隐藏下拉内容?

我已经用实体化库做了一个下拉菜单。它包含项目列表。现在我想在所有项目的底部查看更多链接。该链接已成功添加,但问题是当我单击该链接下拉列表/选择被关闭时。

const select = document.querySelector("select");

const fillSelect = (newOptions) => {
   const options = select.querySelectorAll("option");
   options.forEach((x) => x.remove());
   newOptions.forEach((opt) => {
      
      const optionElement = document.createElement("option");
      optionElement.innerHTML = opt;
      select.appendChild(optionElement);
   });
   updateSelect();
};

const addViewMoreLink = () => {
  const link = document.createElement('div');
  link.innerHTML = 'View more';
  link.addEventListener('click', e => {
    e.preventDefault();
    e.stopPropagation();
    return false;
  })
  const dropdownContent = select.parentNode.querySelector(".dropdown-content");
  dropdownContent.appendChild(link);
}


const updateSelect = () => {
  window.M.FormSelect.init(select, {});
  
  
}

window.onload = function(){
  fillSelect(["Option 1", "Option 2", "Option 3"]);
  addViewMoreLink() …
Run Code Online (Sandbox Code Playgroud)

html javascript css materialize

6
推荐指数
1
解决办法
213
查看次数

How to get the element which are diagonal to a certain index in an array which represents a rectangle

Consider an array whose length will be always product of two numbers. For below array l is 4 and w is 5.

There is also a given index. I want to get the two arrays containing elements which lie on the diagonal line which passes through that particular index.

[
    0,  1,  2,  3,  4
    5,  6,  7,  8,  9
    10, 11, 12, 13, 14
    15, 16, 17, 18, 19
]  

index = 7 => [3, 7, 11, 15] …
Run Code Online (Sandbox Code Playgroud)

javascript arrays algorithm

5
推荐指数
1
解决办法
171
查看次数