Category "numbers"

Javascript. Reduce an array by adding only odd numbers. Javascript returns NaN when I use %2 on a number with if [duplicate]

I am trying to sum all odd numbers of an array. The following method does not work and returns NaN. Could someone explain me why? I found a wo

Given a sequence of integers, return the sum of all the integers that have an even index, multiplied by the integer at the last index

This is my solution and it passes some of the tests, but not all of them. Can anyone help me and explain why? Thank you :) function evenLast(numbers) { let su

How to extract prime numbers from a fibonacci series in C++?

Please help my code is as follows. I have found out the Fibonacci series within a range successfully but I am finding it difficult to extract the prime numbers

Converting words to numbers

I have problem converting words into numbers like Input: Five Thousand Six Hundred Thirty two Output: 5632 How can I do this?

Prevent negative inputs in form input type="number"?

I want to restrict user input to positive numbers in an html form. I know you can set min="0", however it is possible to bypass this by manually entering a ne

How to separate range of integers into two equal parts

I have an array of integers like this one int [] num = {5, 8, 1, 1, 2, 3, 2} and I want to divide it into 2 parts, so that the total of 2 sets will be as equ

How can I extract a number from a string in JavaScript?

I have a string in JavaScript (e.g #box2) and I just want the 2 from it. I tried: var thestring = $(this).attr('href'); var thenum = thestring.replace( /(^.+)(\

Create a unique number with javascript time

I need to generate unique id numbers on the fly using javascript. In the past, I've done this by creating a number using time. The number would be made up of t

Postscript: how to convert a integer to string?

In postscript , the cvs *operator* is said to convert a number to a string. How should I use it ? I tried : 100 100 moveto 3.14159 cvs show or 100 100 movet

How can I generate a random number in a certain range?

How can I create an app that generates a random number in Android using Eclipse and then show the result in a TextView field? The random number has to be in a r

Finding the 1500000th Fib Number Using C++

I wrote the following code to find the 1500000th Fibonacci number(Please ignore horrible indenting, I wrote this in about 2 minutes). I need it as a string. Thi

Lazy Catalan Numbers in Haskell

How might I go about efficiently generating an infinite list of Catalan numbers? What I have now works reasonably quickly, but it seems to me that there should

Remove insignificant trailing zeros from a number?

Have I missed a standard API call that removes trailing insignificant zeros from a number? var x = 1.234000; // to become 1.234 var y = 1.234001; // stays 1.234

Convert number to alphabet letter

I want to convert a number to its corresponding alphabet letter. For example: 1 = A 2 = B 3 = C Can this be done in javascript without manually creating the