how to do Destructuring Ecmascript 6? - ecmascript-6

I am new to ES6 concepts. I have tried many solutions on Stackoverflow but none of them helped me
So this Hackerrank question I have tried many solutions but i am getting error
Question is:
var states = [['Tamilnadu'], ['Punjab', 'Haryana']];
Define Chennai and Chandigarh variables using Destructuring so that variables Chennai = ['Tamilnadu'], Chandigarh = ['Punjab', 'Haryana']
Note: Make sure you have exported the destructured variable Chennai and Chandigarh.
My solution is:
const states=[];
var [Chennai,Chandigarh]=[['Tamilnadu'],['Punjab','Haryana']];
module.exports = {states:[Chennai,Chandigarh]};
The error I am getting is:
How can I solve this problem?

Related

How to Use .as Exported File from PhysicsEditor

The question was here for a long time with bounty and no satisfying solution for me. I erased the first post and am posting instead a question that can be answered quickly with a yes or no so I can proceed with my doings.
If you could answer it really fast before it's deleted by "not a good question". Is using a custom shape from PhysicsEditor to Nape the same as doing it with Box2D? (ofc changing syntax)
If you could then give a look in that link then say it's the same process in Nape that'll be enought thanks.
I ask this because I found the Box2D tutorial easier to follow so far.
public var floor:Body;
floor = new Body(BodyType.STATIC);
var floorShape:PhysicsData = new PhysicsData();
floor.shapes.add(floorShape); // Error: Implicit coercion of a value of type PhysicsData to an unrelated type nape.shape:Shape.
floor.space = space;
Update:
According to a comment on this blog post, it sounds like recent versions of Nape have broken compatibility with the physics editor. Specifically, the graphic and graphicUpdate properties no longer exist on body objects. The solution suggested is to remove references to those properties.
I'm not in a position to be able to test this, but you could try updating the createBody method of your floor class as follows:
public static function createBody(name:String /*,graphic:DisplayObject=null*/):Body {
var xret:BodyPair = lookup(name);
//if(graphic==null) return xret.body.copy();
var ret:Body = xret.body.copy();
//graphic.x = graphic.y = 0;
//graphic.rotation = 0;
//var bounds:Rectangle = graphic.getBounds(graphic);
//var offset:Vec2 = Vec2.get(bounds.x-xret.anchor.x, bounds.y-xret.anchor.y);
//ret.graphic = graphic;
/*
ret.graphicUpdate = function(b:Body):void {
var gp:Vec2 = b.localToWorld(offset);
graphic.x = gp.x;
graphic.y = gp.y;
graphic.rotation = (b.rotation*180/Math.PI)%360;
}
*/
return ret;
}

SML Issue with a function creating another function

Keep in mind, this is part of a homework assignment - so please, no direct answer. I just need some help in finding out the answer, so a link to a tutorial to help me understand the material would be great.
SML code:
datatype 'ingredient pizza =
Bottom
| Topping of ('ingredient * ('ingredient pizza));
datatype fish =
Anchovy
| Shark
| Tuna;
(* Testing Pizza Objects *)
val my_pizza1 = Topping(Tuna, Topping(Shark, Topping(Anchovy, Bottom)));
val my_pizza2 = Topping(Shark, Topping(Tuna, Topping(Anchovy, Bottom)));
val my_pizza3 = Topping(Anchovy, Topping(Shark, Topping(Tuna, Bottom)));
(* My Function Start *)
fun rem_ingredient Bottom = Bottom
| rem_ingredient(t) = fn(Topping(p)) => Topping(t, rem_ingredient(p))
| rem_ingredient(Topping(t,p)) = Topping(t, rem_ingredient(p));
(* My Function End *)
If I call the function rem_ingredient with 1 parameter
val rem_tuna = rem_ingredient Tuna;"
I should get a function that can then call
rem_tuna my_pizza3;
to remove Tuna from pizza3
If I call the same function with 2 parameters
rem_ingredient Tuna my_pizza2;
I should directly remove Tuna from the pizza2 object with the 2 parameters.
The Problem:
I keep getting the error: syntax error: replacing EQUALOP with DARROW on the 3rd constructor of rem_ingredient, I know I'm missing something that is probably obvious. We just start learning SML last week in Programming Languages and I'm still trying to understand it. Anyone pointing me in direction would be appreciated.
Again, no direct answer please, I want to learn the material, but I'm not sure what I'm trying to fix.
To get rid of the syntax error you need to put parentheses around the fn expression (since the following | pattern is otherwise taken to be part of the fn).
However, that is not your real problem here. The function as written does not have a consistent type, because the second case returns a function while the others do not.

AS3: Getting values of objects by referencing their name

I'm reading XML and attaching values to objects in two seperate movieclips. Like this
Map01:
Marker01.name = hello there
Marker01.short = hel
Marker01.value = 12
Map02:
Marker02.name = hello there
Marker02.short = hel
Marker02.value = 99
Now I'm clicking on Marker01 in Map01 and get its name and value. I want to compare its value to that of Marker01 in Map02, using the name, or better yet .short because the names are long and use special characters/spaces. How do I do this? I've pretty much tried everything that seemed logical!
EDIT: sample code for clarification
var marker01:mc_marker = new mc_marker();
marker01.name="hello there";
marker01.short="abc";
marker01.val="99";
marker01.x=10;
marker01.y=10;
this.mc_map01.addChild(marker01);
var marker02:mc_marker = new mc_marker();
marker02.name="hello there";
marker02.short="abc";
marker02.val="20";
marker02.x=10;
marker02.y=10;
this.mc_map02.addChild(marker02);
marker01.addEventListener(MouseEvent.MOUSE_UP, showMarkerInfo);
marker02.addEventListener(MouseEvent.MOUSE_UP, showMarkerInfo);
function showMarkerInfo(event:MouseEvent):void {
txt_ms.text=event.target.short;
txt_mv.text=event.target.val;
if (event.target.short==mc_map02.marker02.short){
txt_mvi.text="here should be the marker02 value";
}
}
You have a typo there. Map02 use Marker1 things.
If its a typo in Stackoverflow,
this.getChildByName( "Marker01" ) will return you the movieclip, buy its name. take care though, as "name" is what it searches for. You used "hello there" when you should put Marker01 as the name. I would suggest you put a property called "data" and put the xml info in it so it doesn't conflict.
In the end you have:
if( this.getChildByName( "Marker01" ).data.value == this.getChildByName( "Marker02" ).data.value ).
I assume this is because you generate Marker0X at runtime and you can't declare some variables and use them directly.
Browny points if you make "data" a instance of a custom class where you can compare two "data". If you need more help, add a comment ^_^

1050 Cannot assign to a non-reference value as3

I'm having some trouble with the error "1050: Cannot assign to a non-reference value." I'm still fairly new to coding, and so being unable to fix this error is frustrating, any help will be greatly appreciated.
var PracticeDummyHealth:int=50
var PlayerAttack:int=20;
public function PlayerAttackFunction(){
if(PracticeDummyHealth>0){
PracticeDummyHealth-PlayerAttack=PracticeDummyHealth;
}
}
An grammar construct which is not a Property/Variable name is on the left of the = assignment operator:
// expression = expression
PracticeDummyHealth-PlayerAttack=PracticeDummyHealth;
// which makes as much sense to ActionScript as .. it's not an equation solver :)
// 100 - 50 = 100
Compare with this valid code:
// variable = new_value
PracticeDummyHealth = PracticeDummyHealth - PlayerAttack;
// or
PracticeDummyHealth -= PlayerAttack;
Note that a "reference" (read: Property/Variable name) appears on the left of the = (or compound -=) in both of these cases. This terminology comes from the specification which deals with l-values and it is slightly unfortunate it doesn't yield a nicer error message here.

Linq to SQL : How do I get the property values from a query's results?

I m just starting with microsoft (MVC,C#, LINQ), so far so good, but i have a question about LINQ uses, How do i get the value form a LINQ like this one?
var x = from a in db.tablex
where a.eventID == eventID
select new
{
owner = a.owner,
shipper = a.shipper,
consignee = a.consignee
};
I try something like "r.owner" inside a foreach to get the value retrieved from DB
foreach (var r in x)
but its not working.. i dont get intellisense either.. how do i get the value??. I saw several examples and it seems to work like this, but for some reason its not working.. Thanks
Ok guys here was the thing, (it wasnt the typo it was just in the post), i was missing a using :
using System.Reflection;
with this C# automatically creates a class from them, and now it works
What a noob of me =).
foreach (var r in x)
{
var owner = r.owner;// not x.owner
}