I wanted to extend String object prototype with some utility method. It worked, but the performance was surprisingly low. Passing a string to a function is 10x times faster than overriding the String.prototype method that is doing the same thing. To make sure this really happens I created a very simple count() function and the corresponding methods. (I was experimenting, and created three di
我想用一些实用的方法来扩展String对象的原型。 它的工作,但表现惊人的低。 将一个字符串传递给一个函数比重写String.prototype方法执行速度快10倍。 为了确保这真的发生,我创建了一个非常简单的count()函数和相应的方法。 (我正在试验,并创建了三种不同版本的方法。) function count(str, char) { var n = 0; for (var i = 0; i < str.length; i++) if (str[i] == char) n++; return n; } String.pro
I am trying to make two panels which can be opened and closed by two buttons. FIDDLE All is working fine, when I do like this: Open red panel. Open green panel. Close red panel. In this case red panel is hiding behind green during animation. But when I do like this: Open green panel. Open red panel. Close green panel. The green panel always in front of red panel during anima
我正在尝试制作两个可通过两个按钮打开和关闭的面板。 小提琴 所有工作都很好,当我这样做时: 打开红色面板。 打开绿色面板。 关闭红色面板。 在这种情况下,红色面板在动画过程中隐藏在绿色背后。 但是当我这样做时: 打开绿色面板。 打开红色面板。 关闭绿色面板。 动画期间,绿色面板总是位于红色面板的前方。 但是第一个打开的面板有z-index: 9 ,第二个打开的面板的z-index: 10 。 请帮我解决问
I have an array like this: var arr1 = ["a", "b", "c", "d"]; How can I randomize / shuffle it? The de-facto unbiased shuffle algorithm is the Fisher-Yates (aka Knuth) Shuffle. See https://github.com/coolaj86/knuth-shuffle You can see a great visualization here (and the original post linked to this) function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex;
我有一个这样的数组: var arr1 = ["a", "b", "c", "d"]; 我如何随机化/洗牌? 事实上的无偏洗牌算法是Fisher-Yates(又名Knuth)Shuffle。 请参阅https://github.com/coolaj86/knuth-shuffle 你可以在这里看到很棒的视觉效果(和原文链接到这里) function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !== cur
I'm trying to do 3D trilateration in Javascript using https://github.com/gheja/trilateration.js and it seems to be working. However, certain simple cases should be yielding solutions but they are not. For example: var p1 = {x:69, y:0, r:69, z:0} var p2 = {x:0, y:50, r:50, z:0}; var p3 = {x:0, y:80, r:80, z:0}; trilaterate(p1, p2, p3, false) This seems like a ridiculously simple example
我正在尝试使用https://github.com/gheja/trilateration.js在Javascript中执行3D三角测量,并且它似乎正在工作。 但是,某些简单的案例应该是提供解决方案,但不是。 例如: var p1 = {x:69, y:0, r:69, z:0} var p2 = {x:0, y:50, r:50, z:0}; var p3 = {x:0, y:80, r:80, z:0}; trilaterate(p1, p2, p3, false) 这看起来像一个可笑的简单例子,它应该在x:0,y:0产生一个解决方案,但是这个函数告诉我没有解决方案。
In this D3.js graph I'm using the magic numbers 20 when the line is straight and 30 when the line is at an angle as the margin to withdraw from the path in order to add a margin between the circles (graph nodes) and the paths (graph edges). I'm also using the fairly random number 1.5 as a multiplier to further the distance from the circle of the path's end, since it has a marker-end
在这个D3.js图中,我使用了直线时的魔术数字20和直线作为边缘时的30作为边距从路径中退出,以便在圆圈(图形节点)和路径(图形边缘)。 我还使用相当随机的数字1.5作为乘数来增加距离路径末端圆的距离,因为它有一个marker-end 。 给定19的圆半径和箭头路径坐标M0,0 V4 L2,2 Z ,我认为应该有可能计算路径应该具有的圆的准确距离(“边距”),但是我的数学技能只是没有不起作用了。 我还假设可以找出路径的方向,因此不再需
I have a pair of fixed location sensors (infrared) that bounce a signal off of a reflector to a fixed receiver (all 3 devices are on a single PCB, [transmitter, receiver, transmitter]). The data given to me by the API of this device is the range from each sensor to the reflector (hand, table, anything). My question is this: using the above data, how can I determine a relative X position of the
我有一对固定的位置传感器(红外线),将信号从反射器反射到固定接收器(所有3个设备都位于单个PCB上,[发射器,接收器,发射器])。 这个设备的API给我的数据是从每个传感器到反射器的范围(手,桌子,任何东西)。 我的问题是:使用上面的数据,我怎样才能确定反射器的相对X位置。 我相当肯定这是一个微不足道的问题,但我的大脑正在画空白。 每个传感器的数据范围从0到240。 var pos = 120 + (ranges.left - ranges.rig
I've made a Google Apps Script deployed as a standalone web app using HTMLService that provides a simple front end to enter budget data into a Google Spreadsheet. I'm using JQuery Mobile for some of the javascript as well as to style it a mobile-friendly manner, as my main use case for this app is to enter purchases from my mobile. My problem is that on a mobile browser, the app doesn&
我已经使用HTMLService将Google Apps脚本部署为独立的Web应用程序,该应用程序提供了一个简单的前端,用于将预算数据输入到Google Spreadsheet中。 我为一些javascript使用JQuery Mobile,并将其设置为适合移动设备的方式,因为此应用程序的主要用例是从我的手机输入购买内容。 我的问题是,在移动浏览器上,应用程序无法正确缩放。 这是浏览器的宽度,但它就像是“缩小”一样。 所有控件在手机上基本无法使用。 如果脚本嵌
Any idea or pseudo code for a Non-recursive, iterative based negamax algorithm? I use negamax as the search heart of my Chess AI. My engine is written in JavaScript and according to the literature can benefit 4x if iteration was used over recursion. The JavaScript to C penalty is about 3x slower in terms of node depth. This one tweak could level the playing field, but take both factors wit
非递归迭代的negamax算法的任何想法或伪代码? 我使用negamax作为我的国际象棋AI的搜索核心。 我的引擎是用JavaScript编写的,根据文献,如果递归使用迭代,则可以获得4倍的收益。 JavaScript到C的惩罚在节点深度方面慢了大约3倍。 这一个调整可以平衡比赛场地,但同时考虑到两个因素: 而不是更长的negamax代码。 类似的递归代码是我的“静态交换评估”(SEE) function _see(sq, fen, depth, maxDepth, color, chess)
Trying to figure out how to store some useful data for chess games programming. I decided to store rays emitted by on-board chessmen in a Raycaster; This question is about the implementation of this structure. TL;DR (for chess gamers only...) first of all, I have identified three kinds of rays : Ray.NORMAL or Ray.FULL: they are emitted by all chessmen but not pawns, in an iterative way (
试图找出如何为国际象棋游戏编程存储一些有用的数据。 我决定将由机载西洋棋棋子发出的光线存储在雷克斯特(Raycaster)中; 这个问题是关于这个结构的实现。 TL; DR(仅限国际象棋游戏玩家...) 首先,我已经确定了三种射线: Ray.NORMAL或Ray.FULL:它们是由所有棋子排出而不是棋子,以反复的方式(白嘴鸦,主教,女王)或不是(骑士和国王) Ray.CAPTURE:仅由典当,左前方和/或右前方拍摄发出 Ray.OFFSET:当前
I'm having some problems with my assignment, which was to make chess pieces move freely across the board without the use of ids in native javascript. I have managed to set them on board and have also tried with getting coordinates from clicking on a piece, then getting coordinates from clicking somewhere on board and assigning the chosen piece those newly acquired coordinates, but nothing se
我在分配任务时遇到了一些问题,这是为了让棋子在本地JavaScript中不使用id而自由移动。 我设法将它们设置在船上,并尝试通过点击一块来获得坐标,然后通过单击船上某处获得坐标并将所选择的那些分配给新获取的坐标,但似乎没有任何工作正确。 我真的很感谢一些帮助:) <head> <meta charset="utf-8"> <style> body { padding: 20px; } h1 { text-align: center } table {