numbers

How to target e negative number from an array, and get the sum of all positive numbers?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 17:24:54
I am trying to figure it out how to target negative numbers in an array. I have this function SummPositive( array ) { } SummPositive( [ 1, 2, 3, 4, 5, -2, 23, -1, -13, 10,-52 ] ); This is an array with negative and positive numbers.How to target all negative numbers from array, when you don't know how many negative numbers are in array? For example, I am trying to...loop to entire array, find the positive numbers, store them in another array, and make a sum (1+2+3+4+5+10+23) . But i am noob, and i don't how to do that. If possible to do this only with native js Just make a condition to check

how to create unique integer number from 3 different integers numbers(1 Oracle Long, 1 Date Field, 1 Short)

南笙酒味 提交于 2019-12-05 17:13:15
问题 the thing is that, the 1st number is already ORACLE LONG, second one a Date (SQL DATE, no timestamp info extra), the last one being a Short value in the range 1000-100'000. how can I create sort of hash value that will be unique for each combination optimally? string concatenation and converting to long later: I don't want this, for example. Day Month 12 1 --> 121 1 12 --> 121 回答1: When you have a few numeric values and need to have a single "unique" (that is, statistically improbable

Ideas about Generating Untraceable Invoice IDs

落爺英雄遲暮 提交于 2019-12-05 16:52:05
问题 I want to print invoices for customers in my app. Each invoice has an Invoice ID . I want IDs to be: Sequential (ids entered lately come late) 32 bit integers Not easily traceable like 1 2 3 so that people can't tell how many items we sell. An idea of my own: Number of seconds since a specific date & time (e.g. 1/1/2010 00 AM). Any other ideas how to generate these numbers ? 回答1: I don't like the idea of using time. You can run into all sorts of issues - time differences, several events

棘手的JavaScript面试题

£可爱£侵袭症+ 提交于 2019-12-05 16:42:27
1、意外的全局变量 在以下代码中, typeof a 和 typeof b 的值分别是什么: function foo() { let a = b = 0; a++; return a; } foo(); typeof a; // => ???typeof b; // => ??? 答案:让我们仔细看看第2行: let a = b = 0 。这个语句确实声明了一个 局部变量 a 。但是,它也声明了一个 全局 变量 b 。 注: b 是一个偶然创建的全局变量。 在浏览器中,上述代码相当于: function foo() { let a; window.b = 0; a = window.b; a++; return a; } foo(); typeof a; // => 'undefined' typeof window.b; // => 'number' typeof a 是 ' undefined '。 变量 a 仅在 foo() 范围内声明,在外部范围内不可用。 typeof b 等于' number '。 b 是一个值为 0 的 全局变量 。 2、鹰眼测试 numbers 数组内容是什么: const length = 4; const numbers = []; for (var i = 0; i < length; i++);{ numbers.push(i + 1);

How can we decide the total no. of buckets for a hive table

泪湿孤枕 提交于 2019-12-05 16:31:20
i am bit new to hadoop. As per my knowledge buckets are fixed no. of partitions in hive table and hive uses the no. of reducers same as the total no. of buckets defined while creating the table. So can anyone tell me how to calculate the total no. of buckets in a hive table. Is there any formula for calculating the total number of buckets ? Lets take a scenario Where table size is: 2300 MB, HDFS Block Size: 128 MB Now, Divide 2300/128=17.96 Now, remember number of bucket will always be in the power of 2. So we need to find n such that 2^n > 17.96 n=5 So, I am going to use number of buckets as

Localization of numeric number in Rails

蹲街弑〆低调 提交于 2019-12-05 16:11:22
[Sorry for the new post, but my first one was focusing to arabic/persian numbers but it seems the issue is larger.] I wonder if someone had done a gem to handle the localization of numeric number in ruby/rails. I18n official locales ( https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale ) seems not to take care of that. It's kind of complex to do by helpers. Arabic is simple: ٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩ Persian too: ۰ ١ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹ ۱۰ But all languages don't match 1-1 conversion with english, Chinese for example: 0: 〇 (零) líng 1: 一 (壹) yī 2: 二 (Simplified:贰;Traditional:貳) èr 3: 三

ForkJoinPool详解

可紊 提交于 2019-12-05 15:14:27
本文的主要目的是介绍 ForkJoinPool 的适用场景,实现原理,以及示例代码。 说在前面 可以说是说明,也可以说下面是结论: ForkJoinPool 不是为了替代 ExecutorService,而是它的补充,在某些应用场景下性能比 ExecutorService 更好。 ForkJoinPool 主要用于实现“分而治之”的算法,特别是分治之后递归调用的函数,例如 quick sort 等。 ForkJoinPool 最适合的是计算密集型的任务,如果存在 I/O,线程间同步,sleep() 等会造成线程长时间阻塞的情况时,最好配合使用 ManagedBlocker。 使用 首先介绍的是大家最关心的 Fork/Join Framework 的使用方法,用一个特别简单的求整数数组所有元素之和来作为我们现在需要解决的问题吧。 问题:计算1至10000000的正整数之和。 方案一:最为普通的for循环解决 最简单的,显然是不使用任何并行编程的手段,只用最直白的 for-loop 来实现。下面就是具体的实现代码。 为了面向接口编程,下面我们把计算的方法定义成接口,不同的方案书写不同的实现即可 public interface Calculator { /** * 把传进来的所有numbers 做求和处理 * * @param numbers * @return 总和 */ long

jquery: set min max input in option type number

走远了吗. 提交于 2019-12-05 15:08:49
问题 I have this part of code <input type="number" min="2" max="10" step="2" id="contact" oninput="new_sum"> In the field I can insert a number > 10 and < 2. How can I limit it? 回答1: add an onchange function and set the value if it's out of the range. $(function () { $( "#numberBox" ).change(function() { var max = parseInt($(this).attr('max')); var min = parseInt($(this).attr('min')); if ($(this).val() > max) { $(this).val(max); } else if ($(this).val() < min) { $(this).val(min); } }); }); <script

How can I use numbers with angular.js without comma and dot?

。_饼干妹妹 提交于 2019-12-05 14:43:06
I m new at angular.js I have a ID column in my grid so I dont want to use formatted numbers with comma or dot. Should I use replace method or related regex expression? I used like: {{value | number: 0}} For example(10000 is 10,000 in my application I want to use like 10000) Then don't use the number filter? Else, if you want it to be a number type create a custom filter: app.filter('customNumber', function() { return function(value) { return parseInt(value, 10) //convert to int } }) template: {{value | customNumber}} 来源: https://stackoverflow.com/questions/33561186/how-can-i-use-numbers-with

Scaling Random Bytes to Selected Integer Range

孤街浪徒 提交于 2019-12-05 12:02:38
I have a file of true random bytes. I want a function that returns a random integer in the range given by taking a byte from the file and scaling it. (is this the right word?) public int getInt(int l, int h) throws IOException { int m = (h - l) + 1; // number of ranges needed int r = 256 / m; // size of byte range int x = (r * m) - 1; // maximum allowable byte value int b; do { try { // get random byte from file b = ram.readUnsignedByte(); } catch (EOFException e) { // catch EOF, reset pointer b = 255; ram.seek(0); // and set b to maximum value } // so test will fail. } while(b > x); // if