Jump to content

smus

Members
  • Content Count

    134
  • Joined

  • Last visited

Community Reputation

0 Neutral

About smus

  • Rank
    Member

Recent Profile Visitors

7,150 profile views
  1. smus

    JSON and object

    Thanks
  2. smus

    JSON and object

    No other way? No kinda search method for big and complex objects?
  3. smus

    JSON and object

    Why is map() method often used for these reasons? Might that be because the structure is complex and I know the name of the property and I am not sure about its hierarchical disposition? For example, a = { first : ['propertyOne' = 'po', 'propertyTwo' = 'pt'], second : [smallObj = {s1:'s1', s2: 's2', s3: 's3'}, smallObj2 = {s1:'s1'}, ['a1', 'a2']], third : ['t1', [{'whatIWantToFind':'someInfo'}], t3, 'abcdef'] } I have to find the 'whatIWantToFind' property inside a object. I know it is inside the object, but I don't know where exactly it is. Do I need to use a map() or any other method for it?
  4. smus

    JSON and object

    If I have a JSON data, can I apply to it as if it is a JS Object, or I should use JSON.parse() first? Will it skip the property names quotes? ("name":"value" or name:"value") If there are some associative arrays inside and the structure is complex, is it easier to use array.map() method or it is better to apply to the properties directly?
  5. smus

    equation solver

    It's a part of a more complex task. 5 is already a result, it is a GCD (greatest common divisor) of those 2 integers (210,65). They are function input parameters, but now it has to return x and y, not only GCD.
  6. smus

    equation solver

    yes, it's needed to be solved by js
  7. smus

    equation solver

    How do I solve the equation: 210x+65y=5 x and y must be integers
  8. smus

    Code optimization

    Where n is the amount of nested loops? According to your explanation, it is better to have several independent loops, than one nested loop: for(){} for(){} for(){} for(){} would be faster than: for(){ for(){} }
  9. smus

    Array into a formula

    Exactly, right. The precedence goes pair(* and /) over pair(+ and -) and the Win Calc must be set to a kind of formula mode to use precedence order, otherwise it counts numbers from left to right as they are. Thanks!
  10. smus

    Array into a formula

    eval() works in this case, but I am not sure what the right priority is (operator precedence) in Javascript. Some websites has info that divistion(/) has the highest priority then goes multiplication, addition and subtraction. That is strange, because usually multiplication is the first. 1-2+3*4/5 = 1.4 according to JS compliler (/ then * then - then +, no idea why it counts like that) 1-2+3*4/5 = 1.6 according to Windows Calc (I guess, it counts without any priority) 1-2+3*4/5 = -3.4 if we use the correct operator precedence (* / + -) What I was taught in high school is that the correct precedence must be: * / + - Never thought that there might be another order in programming languages.
  11. smus

    Code optimization

    Thanks, perfect! So, what I can learn from it, including additional loops significantly increases the script's implementation time. Am I right?
  12. smus

    Code optimization

    It scored 70% Passed only one more of performance tests (large_extreme: large test with all 1s/0s, length = ~100,000, approx 0.100s) https://app.codility.com/demo/results/training95UXWY-GN8/
  13. smus

    Array into a formula

    Elements of an array of a math formula look like this: a = [1,'+',2,'-',3,'*',4,'/',5]; How do I perform all the arythmetic actions between those numbers. The array elements may be different, because they are added dynamically. It would not be difficult if I didn't have to prioritize the actions (/,*,_,-). I tried using splice() method, but something goes wrong. Maybe I can somehow sort the elements according to the math actions priority?
  14. smus

    Code optimization

    How can I optimize this code? It's correct, but performance tests scored just 20%: function solution(A){ var al = A.length, c = 0; for(var x=0;x<al;x++){ if(A[x] == 0){ for(var y=x;y<al;y++){ if(A[y] == 1){ c++;} } } } return c; } console.info(solution([0,1,0,1,0,1,0])); //6 Here is the link to the task: https://app.codility.com/demo/results/trainingM8PUJV-HEU/
  15. smus

    Array declaration

    a() redim a(n) now it works, thanks
×